Rob A'Court | 21 Apr 12:45 2016

Issue using variable length fields with Erlang ODBC

When querying variable length fields using ODBC in Erlang, the response returned seems to be gibberish. I’ve posted this on the questions board and it has been suggested that this is a real bug.

 

We can query tables in a MS SQL Server database but if the table contains a VarCharMax or NVarCharMax field (both variable length) then the result returned is not what we expect. For NVarCharMax a binary is returned which has part of the original query and other seemingly random data as if it’s the wrong area of memory. For VarCharMax an empty list is always returned.

 

In our particular scenario we are trying to get a ShowPlanXML from MS SQL Server which comes back as a NVarCharMax and there is no way of converting it to a fixed length field type to work around the issue.

 

The issue does not seem to be with the ODBC driver as trying the same thing in python works fine.

 

Here is what we are trying to do in Elixir:

 

:odbc.start

{:ok, connection} = :odbc.connect('Driver={ODBC Driver 11 for SQL Server}; Server=TheServer;Uid=sa;Pwd=password;Database=TheDatabase',[])

IO.inspect :odbc.sql_query(connection, 'set showplan_xml on')

IO.inspect :odbc.sql_query(connection, 'Select * from customers'), limit: 9000

 

 

Here is the equivalent in python that works fine:

 

#!/usr/bin/env python

import pyodbc

conn = pyodbc.connect('Driver={ODBC Driver 11 for SQL Server}; Server=TheServer;Uid=sa;Pwd=password;Database=TheDatabase')

cur = conn.cursor()

cur.execute('set showplan_xml on')

cur.execute('Select * from customers')

 

for row in cur :

  print row     

 

 

Many thanks!

 

Rob

_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs
Aleksander Nycz | 16 Apr 07:33 2016
Picon

gen_server error report issue

Hello,

I think I've found some problem in gen_server error report:

when terminate callback throw errors then earlier errors (eg. from handle_call callback) is not reported.

Please compile and run provided simple_server.erl module, that implement gen_server behaviour:

(compilation12836 <at> zyndram.krakow.comarch)4> simple_server:start_link(false).
{ok,<0.128.0>}
(compilation12836 <at> zyndram.krakow.comarch)5> simple_server:perform(false).
ok
(compilation12836 <at> zyndram.krakow.comarch)6> simple_server:perform(true).
** exception exit: perform_error_in_handle_call
     in function  simple_server:handle_call/3 (loadController/src/simple_server.erl, line 89)
     in call from gen_server:try_handle_call/4 (gen_server.erl, line 629)
     in call from gen_server:handle_msg/5 (gen_server.erl, line 661)
     in call from proc_lib:init_p_do_apply/3 (proc_lib.erl, line 240)
(compilation12836 <at> zyndram.krakow.comarch)7>
=ERROR REPORT==== 16-Mar-2016::15:36:35 ===
** Generic server simple_server terminating
** Last message in was {perform,true}
** When Server state == {state,false}
** Reason for termination ==
** {perform_error_in_handle_call,
       [{simple_server,handle_call,3,
            [{file,"loadController/src/simple_server.erl"},{line,89}]},
        {gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,629}]},
        {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,661}]},
        {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]}

In this case we can see that exception was thrown 'in function  simple_server:handle_call/3 (loadController/src/simple_server.erl, line 89)'

And now please start server in this way:

(compilation12836 <at> zyndram.krakow.comarch)7> simple_server:start_link(true).
{ok,<0.133.0>}
(compilation12836 <at> zyndram.krakow.comarch)8> simple_server:perform(false).
ok
(compilation12836 <at> zyndram.krakow.comarch)9> simple_server:perform(true).

=ERROR REPORT==== 16-Mar-2016::15:37:30 ===
** Generic server simple_server terminating
** Last message in was {perform,true}
** When Server state == {state,true}
** Reason for termination ==
** {throw_error_in_terminate_callback,
       [{simple_server,terminate,2,
            [{file,"loadController/src/simple_server.erl"},{line,141}]},
        {gen_server,try_terminate,3,[{file,"gen_server.erl"},{line,643}]},
        {gen_server,terminate,7,[{file,"gen_server.erl"},{line,809}]},
        {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]}
** exception exit: throw_error_in_terminate_callback
     in function  simple_server:terminate/2 (loadController/src/simple_server.erl, line 141)
     in call from gen_server:try_terminate/3 (gen_server.erl, line 643)
     in call from gen_server:terminate/7 (gen_server.erl, line 809)
     in call from proc_lib:init_p_do_apply/3 (proc_lib.erl, line 240)

Now gen_server is also terminating, but we can only see exception from terminate callback.

Exception that causes gen_server termination is not reported.
I rather expect that both exceptions will be shown.


Regards
Aleksander Nycz


-- Aleksander Nycz Chief Designer Telco_021 BSS R&D Comarch SA Phone: +48 17 785 5909 Mobile: +48 691 464 275 website: www.comarch.pl
%%%-------------------------------------------------------------------
%%%  <at> author ANycz
%%%  <at> copyright (C) 2016, <COMPANY>
%%%  <at> doc
%%%
%%%  <at> end
%%% Created : 16. mar 2016 15:30
%%%-------------------------------------------------------------------
-module(simple_server).
-author("ANycz").

-behaviour(gen_server).

%% API
-export([start_link/1, perform/1]).

%% gen_server callbacks
-export([init/1,
    handle_call/3,
    handle_cast/2,
    handle_info/2,
    terminate/2,
    code_change/3]).

-define(SERVER, ?MODULE).

-record(state, {throw_error_in_terminate_callback :: boolean()}).

%%%===================================================================
%%% API
%%%===================================================================


perform(ThrowError) ->
    gen_server:call(?MODULE, {perform, ThrowError})
.

%%--------------------------------------------------------------------
%%  <at> doc
%% Starts the server
%%
%%  <at> end
%%--------------------------------------------------------------------
-spec(start_link(ThrowError::boolean) ->
    {ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
start_link(ThrowError) ->
    gen_server:start_link({local, ?SERVER}, ?MODULE, ThrowError, []).

%%%===================================================================
%%% gen_server callbacks
%%%===================================================================

%%--------------------------------------------------------------------
%%  <at> private
%%  <at> doc
%% Initializes the server
%%
%%  <at> spec init(Args) -> {ok, State} |
%%                     {ok, State, Timeout} |
%%                     ignore |
%%                     {stop, Reason}
%%  <at> end
%%--------------------------------------------------------------------
-spec(init(Args :: term()) ->
    {ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
    {stop, Reason :: term()} | ignore).
init(ThrowError) ->
    {ok, #state{throw_error_in_terminate_callback = ThrowError}}.

%%--------------------------------------------------------------------
%%  <at> private
%%  <at> doc
%% Handling call messages
%%
%%  <at> end
%%--------------------------------------------------------------------
-spec(handle_call(Request :: term(), From :: {pid(), Tag :: term()},
    State :: #state{}) ->
    {reply, Reply :: term(), NewState :: #state{}} |
    {reply, Reply :: term(), NewState :: #state{}, timeout() | hibernate} |
    {noreply, NewState :: #state{}} |
    {noreply, NewState :: #state{}, timeout() | hibernate} |
    {stop, Reason :: term(), Reply :: term(), NewState :: #state{}} |
    {stop, Reason :: term(), NewState :: #state{}}).

handle_call({perform, false}, _From, State) ->
    {reply, ok, State};
handle_call({perform, true}, _From, State) ->
    erlang:error(perform_error_in_handle_call),
    {reply, ok, State};
handle_call(_Request, _From, State) ->
    {reply, ok, State}.

%%--------------------------------------------------------------------
%%  <at> private
%%  <at> doc
%% Handling cast messages
%%
%%  <at> end
%%--------------------------------------------------------------------
-spec(handle_cast(Request :: term(), State :: #state{}) ->
    {noreply, NewState :: #state{}} |
    {noreply, NewState :: #state{}, timeout() | hibernate} |
    {stop, Reason :: term(), NewState :: #state{}}).
handle_cast(_Request, State) ->
    {noreply, State}.

%%--------------------------------------------------------------------
%%  <at> private
%%  <at> doc
%% Handling all non call/cast messages
%%
%%  <at> spec handle_info(Info, State) -> {noreply, State} |
%%                                   {noreply, State, Timeout} |
%%                                   {stop, Reason, State}
%%  <at> end
%%--------------------------------------------------------------------
-spec(handle_info(Info :: timeout() | term(), State :: #state{}) ->
    {noreply, NewState :: #state{}} |
    {noreply, NewState :: #state{}, timeout() | hibernate} |
    {stop, Reason :: term(), NewState :: #state{}}).
handle_info(_Info, State) ->
    {noreply, State}.

%%--------------------------------------------------------------------
%%  <at> private
%%  <at> doc
%% This function is called by a gen_server when it is about to
%% terminate. It should be the opposite of Module:init/1 and do any
%% necessary cleaning up. When it returns, the gen_server terminates
%% with Reason. The return value is ignored.
%%
%%  <at> spec terminate(Reason, State) -> void()
%%  <at> end
%%--------------------------------------------------------------------
-spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()),
    State :: #state{}) -> term()).
terminate(_Reason, #state{throw_error_in_terminate_callback = false}) ->
    ok;
terminate(_Reason, #state{throw_error_in_terminate_callback = true}) ->
    erlang:error(throw_error_in_terminate_callback),
    ok.


%%--------------------------------------------------------------------
%%  <at> private
%%  <at> doc
%% Convert process state when code is changed
%%
%%  <at> spec code_change(OldVsn, State, Extra) -> {ok, NewState}
%%  <at> end
%%--------------------------------------------------------------------
-spec(code_change(OldVsn :: term() | {down, term()}, State :: #state{},
    Extra :: term()) ->
    {ok, NewState :: #state{}} | {error, Reason :: term()}).
code_change(_OldVsn, State, _Extra) ->
    {ok, State}.

%%%===================================================================
%%% Internal functions
%%%===================================================================
Attachment (smime.p7s): application/pkcs7-signature, 6675 bytes
_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs
Matt Keenan | 13 Apr 15:46 2016
Picon

math:exp() erlang bug on SPARC

Hi,

Just wanted to report a SPARC specific issue with Erlang.

See discussions:
   https://github.com/rabbitmq/rabbitmq-server/issues/132
   https://groups.google.com/forum/#!topic/rabbitmq-users/Gca8vW52gB8

Only happens on SPARC systems does not occur on X86 architecture.
e.g.:

On s11u3 x86:
1> math:exp(-1162.102134881488).
0.0

On s11u3 SPARC:
1> math:exp(-1162.102134881488).
** exception error: an error occurred when evaluating an arithmetic 
expression in function math:exp/1 called as math:exp(-1162.102134881488)

Both systems are running 64-bit Erlang 17.5 in a 64-bit environment.

Has an issue related to this been posted before ?

cheers

Matt
_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs

Heinz Nikolaus Gies | 10 Mar 21:59 2016
Picon
Gravatar

Bug in random seed (definition?) and random:uniform_s/2

This might not be critical any more since seed is deprecated but I encountered a problem with random today when passing in hand crafted seeds.

The definition of a seed is: {integer(), integer(), integer()}

The seed was generated by the method suggested in random:seed:
{erlang:phash2([node()]), erlang:monotonic_time(), erlang:unique_integer()}
This resulted in the seed:

{128631525,-576302453291645741,-576460752303421854}

That seed is valid based on the type specification of seed.

Now entered random:uniform_s/2, by specification it returns a value 1 <= N <= (passed argument) BUT it doesn’t with this seed:

random:uniform_s(10, {128631525,-576302453291645741,-576460752303421854}).
{-1,{23048,-115,-29427}}


Yes I know that  constructing and passing a seed like this is evil,  please don’t get hung on that, it is not my code it’s code I am debugging - I fully agree that it probably should be changed to rand and be done with it, still it looks is a bug.

Cheers,
Heinz

_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs
max_feng | 25 Feb 03:47 2016
Picon

Scheduler hang

On Erlang 18.1, my  application run several weeks, and I found one scheduler hanging for several hourse (But work fine on Erlang-17.5 fine for several months ! ), here is my experiment:

0) my application run several weeks
1) attach
2) run one process on each scheduler
5> [erlang:spawn(fun() -> erlang:process_flag(scheduler, I), io:format("Id: ~p~n", [I]) end) || I <- lists:seq(1, 24) ].
Id: 1
Id: 2
Id: 3
Id: 4
Id: 6
Id: 5
Id: 7
Id: 8
Id: 9
Id: 10
Id: 11
Id: 13
Id: 12
Id: 14
Id: 15
Id: 16
Id: 17
Id: 18
Id: 19
Id: 21
Id: 22
Id: 24
Id: 23

But scheduler-20 not responsed !.

This is run queue length:
6> erlang:statistics(run_queues).
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}

The run queue length of scheduler-20 is 1, and increased by when I rerun [erlang:spawn(fun() -> erlang:process_flag(scheduler, I), io:format("Id: ~p~n", [I]) end) || I <- lists:seq(1, 24) ].


Here is the callstack of scheduler-20, and most schedulers's callstack are the same:

#0  0x0000003895ee4049 in syscall () from /lib64/libc.so.6
#1  0x000000000060f71e in ethr_event_twait ()
#2  0x00000000004d9edc in scheduler_wait ()
#3  0x00000000004e5926 in schedule ()
#4  0x00000000004383c3 in process_main ()
#5  0x00000000004d431f in sched_thread_func ()
#6  0x000000000060ee12 in thr_wrapper ()
#7  0x0000003896207851 in start_thread () from /lib64/libpthread.so.0
#8  0x0000003895ee767d in clone () from /lib64/libc.so.6

But after several hours scheduler-20 resume again !

Max Feng


_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs
Andrzej Trawiński | 24 Feb 23:18 2016
Picon

Missing sockets stats for SCTP

Hi!

I've recently played with the SCTP connections and noticed that when I'm trying to get SCTP socket stats (using inet:getstat(Socket) function) I'm always receiving zero (0) values for sending side options.

...
{ok,[{recv_oct,96},
              {recv_cnt,7},
              {recv_max,16},
              {recv_avg,13},
              {recv_dvi,2},
              {send_oct,0},
              {send_cnt,0},
              {send_max,0},
              {send_avg,0},
              {send_pend,0}]}.
..

This reproduces on both 17.5.6.8 and 18.2.

It shows proper values for TCP sockets, but for SCTP most likely something is wrong with it.
Any ideas on this?

Thanks,
Andrzej
_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs
Tony Wallace | 18 Feb 10:43 2016
Picon

io:get_chars no longer respecting Control-D (eof) in Erlang 18.1

The task is to produce an escript that reads standard input.  The code
that used to work was:

read_stdin() ->
    lists:flatten(read_stdin(io:get_chars(standard_io,"",8192))).
read_stdin(eof) ->
    [];
read_stdin(Data) ->
    [Data|read_stdin(io:get_chars(standard_io,"",8192))].

Now this code causes the program to hang.  If I try the following
command from the erlang prompt:

2> io:get_chars("",10).

and then try to end the input with control-D the command does not
return.  It could be a problem with
the shell intercepting the control-D or io:get_chars could be broken.

Tony Wallace

_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs

Masatake Daimon | 17 Feb 07:08 2016
Picon

Combination of erl flags "+B" and "-smp enable" renders producing crash dumps impossible

Hello,

I found a bug in OTP 18.2.1 on Linux. When the erl flag "+B" is given, 
and SMP is enabled, erts fails to produce a crash dump but instead kills 
itself with SIGUSR2:

> $ erl -smp enable -noshell -eval 'erlang:halt("Hello").'
>
> Crash dump is being written to: erl_crash.dump...done
> Hello
> $ echo $?
> 1
> $ erl -smp disable +B -noshell -eval 'erlang:halt("Hello").'
>
> Crash dump is being written to: erl_crash.dump...done
> Hello
> $ rm erl_crash.dump
> $ erl -smp enable +B -noshell -eval 'erlang:halt("Hello").'
> User defined signal 2
> $ echo $?
> 140
> $ ls erl_crash.dump
> ls: erl_crash.dump: No such file or directory

The reason for this behavior is as follows:
* When the +B flag is given, erl_start() (beam/erl_init.c:2133) skips 
calling init_break_handler().
* But init_break_handler() (sys/unix/sys.c:970) is the only function 
which registers a signal handler for SIGUSR2.
* When a crash dump is being produced, erl_crash_dump_v() 
(beam/break.c:694) sends SIGUSR2 to each scheduler thread.
* Since there is no handler for SIGUSR2, the whole process terminates.

I'm posting the report to the ML instead of submitting a pull request 
because I'm not sure how to fix this properly. This is especially 
problematic for escripts because main() (etc/common/escript.c:459) 
automatically sets the +B flag. I hope someone familiar with these 
things can resolve the problem.

Kind regards,
Masatake Daimon
--

-- 
大門 正岳 <daimon <at> ymir.co.jp>

_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs
José Valim | 6 Feb 17:15 2016
Picon
Gravatar

Internal consistency check failed (with binary matching and orself)

Hello,

We have run into a failed internal consistency check. Here I am reporting the bug as asked. :D


The code is a bit convoluted but that was done in order to provide a minimum test case.

Thank you!


José Valim
Skype: jv.ptec
Founder and Director of R&D
_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs
Ingars | 21 Jan 13:38 2016
Picon
Gravatar

ASN.1. generation with erlc -bber works / erlc -bper - fails

Hi,

I have found an ASN.1 fragment that compiles well with erlc -bber flag but fails with erlc -bper.

> iri <at> ubuntu:~/asn$ erlc -bber TEST.asn
  -> works well

> iri <at> ubuntu:~/asn$ erlc -bper TEST.asn
  -> raises an error
      ------------------------------------------------
      {{badmatch,1799999989},
       [{asn1ct_imm,per_enc_constrained,4,[{file,"asn1ct_imm.erl"},{line,1139}]},
        {asn1ct_imm,per_enc_integer_1,3,[{file,"asn1ct_imm.erl"},{line,1094}]},
        {asn1ct_imm,'-per_enc_integer/4-lc$^0/1-0-',4,
                    [{file,"asn1ct_imm.erl"},{line,248}]},
        {asn1ct_imm,per_enc_integer,4,[{file,"asn1ct_imm.erl"},{line,248}]},
        {asn1ct_gen_per,gen_encode_prim,3,[{file,"asn1ct_gen_per.erl"},{line,121}]},
        {asn1ct_gen_per,gen_encode_user,2,[{file,"asn1ct_gen_per.erl"},{line,98}]},
        {asn1ct_gen,pgen_types,5,[{file,"asn1ct_gen.erl"},{line,123}]},
        {asn1ct_gen,pgen_typeorval,4,[{file,"asn1ct_gen.erl"},{line,105}]}]}
      ------------------------------------------------

With ASN.1 -> C compiler
> asn1c -gen-PER TEST.asn
  -> also works well


File TEST.asn:
------------------------
    TEST DEFINITIONS IMPLICIT TAGS ::=
    BEGIN
      Longitude ::= INTEGER
      {
        oneMicrodegreeEast(10),
        oneMicrodegreeWest(-10),
        unavailable(1800000001)
      } (-1799999999..1800000001)
    END
------------------------


Thanks,

Ingars
/////

_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs
Paul Davis | 21 Jan 06:26 2016
Picon
Gravatar

NIF segfault when using dirty schedulers

Hey all,

I've recently run into a segfault while working with dirty schedulers.
I managed to make a fairly concise reproducing test case at [1]. I
included a stack trace at [2] from when the segfault occurs. This is
definitely a racey segfault as well. I sometimes have to run `rebar
eunit` a handful of times to trigger it.

I'm not hugely familiar with all of the VM internals so I'm at a bit
of a loss on where to start looking further. I did try and get rid of
the requirement for eunit but I couldn't reproduce without it.

This reproduces on both 17.5.6.4 where I found it and 18.2.2. I
haven't tried master or anything of that nature.

Let me know if there's anything else I can do to help debug this.

Thanks,
Paul

[1] https://gist.github.com/davisp/1e71ec7f2f7a70d1b79c
[2] https://gist.github.com/davisp/1e71ec7f2f7a70d1b79c#file-gdb_backtrace-txt
_______________________________________________
erlang-bugs mailing list
erlang-bugs <at> erlang.org
http://erlang.org/mailman/listinfo/erlang-bugs


Gmane