erleans / pgo

Erlang Postgres client and connection pool
Apache License 2.0
80 stars 16 forks source link

badmatch error in pg_pool #39

Closed benbro closed 4 years ago

benbro commented 4 years ago

I got this error in the log:

** Generic server default terminating
** Last message in was {'ETS-TRANSFER',#Ref<0.825018040.2050031153.49530>,
                           <0.18195.0>,#Ref<0.825018040.2049031153.102544>}
** When Server state == {ready,#Ref<0.825018040.2049031153.102544>,
                               #{delay => 0,
                                 idle => #Ref<0.825018040.2049966081.69934>,
                                 idle_interval => 1000,interval => 1000,
                                 next => -566460740002,
                                 poll => #Ref<0.825018040.2049966081.69933>,
                                 slow => false,target => 50}}
** Reason for termination ==
** {{badmatch,
        [{'__info__',<0.913.0>,#Ref<0.825018040.2049966081.69942>,
             {conn,<0.913.0>,
                 {sslsocket,
                     {gen_tcp,#Port<0.11>,tls_connection,undefined},
                     [<0.1350.0>,<0.1129.0>]},
                 ssl,default,
                 #{<<"DateStyle">> => <<"ISO, MDY">>,
                   <<"IntervalStyle">> => <<"postgres">>,
                   <<"TimeZone">> => <<"Etc/UTC">>,
                   <<"application_name">> => <<"app@127.0.0.1">>,
                   <<"client_encoding">> => <<"UTF8">>,
                   <<"integer_datetimes">> => <<"on">>,
                   <<"is_superuser">> => <<"off">>,
                   <<"server_encoding">> => <<"UTF8">>,
                   <<"server_version">> => <<"12.2 (Ubuntu 12.2-4)">>,
                   <<"session_authorization">> => <<"app">>,
                   <<"standard_conforming_strings">> => <<"on">>},
                 true,false,[]},
             {conn,<0.913.0>,
                 {sslsocket,
                     {gen_tcp,#Port<0.11>,tls_connection,undefined},
                     [<0.1350.0>,<0.1129.0>]},
                 ssl,default,
                 #{<<"DateStyle">> => <<"ISO, MDY">>,
                   <<"IntervalStyle">> => <<"postgres">>,
                   <<"TimeZone">> => <<"Etc/UTC">>,
                   <<"application_name">> => <<"app@127.0.0.1">>,
                   <<"client_encoding">> => <<"UTF8">>,
                   <<"integer_datetimes">> => <<"on">>,
                   <<"is_superuser">> => <<"off">>,
                   <<"server_encoding">> => <<"UTF8">>,
                   <<"server_version">> => <<"12.2 (Ubuntu 12.2-4)">>,
                   <<"session_authorization">> => <<"app">>,
                   <<"standard_conforming_strings">> => <<"on">>},
                 true,false,[]}}]},
    [{pgo_pool,delete_holder,2,
         [{file,
              "pgo/src/pgo_pool.erl"},
          {line,385}]},
     {pgo_pool,handle_info,2,
         [{file,
              "pgo/src/pgo_pool.erl"},
          {line,134}]},
     {gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,680}]},
     {gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,756}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}
tsloughter commented 4 years ago

Thanks, it looks like its a case of using a tuple instead of a record biting me. Specifically on that line matching on a 4-tuple instead of a 5-tuple.

benbro commented 4 years ago

Can you explain when it happens? Is there a quick fix? I'm getting this error in production.

tsloughter commented 4 years ago

I can do the quick fix.

I think that function is called when the process using the connection from the pool crashes. To be safe it disconnects that connection and creates a new one.

tsloughter commented 4 years ago

Pushed to master. Can you try that?

I'll try adding a test that reproduces it and verifies the fix before releasing to hex.

tsloughter commented 4 years ago

Verified with a test and pushed that to master. Will make a hex release now.

tsloughter commented 4 years ago

Published pgo 0.11.1

benbro commented 4 years ago

Thank you for the quick fix. I've upgraded to pgo 0.11.1 in production with a manual fix for the transaction issue.