rabbitmq / rabbitmq-erlang-client

Erlang client for RabbitMQ
https://www.rabbitmq.com/
Other
184 stars 127 forks source link

badmatch in amqp_network_connection:handshake causes amqp_connection:start to fail #10

Closed brendanmaguire closed 9 years ago

brendanmaguire commented 9 years ago

We sometimes get the following error in our application which seems to occur because an error happens during the connection handshake.

2014-11-29 02:29:38 =ERROR REPORT====
** Generic server <0.248.0> terminating 
** Last message in was connect
** When Server state == {<0.230.0>,{amqp_params_network,<<"guest">>,<<"guest">>,<<"tasks">>,"mq.example.com",5672,0,0,0,infinity,none,[#Fun<amqp_auth_mechanisms.plain.3>,#Fun<amqp_auth_mechanisms.amqplain.3>],[],[]}}
** Reason for termination == 
** {function_clause,[{amqp_gen_connection,terminate,[{{badmatch,{error,closed}},[{amqp_network_connection,handshake,2,[{file,"src/amqp_network_connection.erl"},{line,190}]},{amqp_network_connection,try_handshake,3,[{file,"src/amqp_network_connection.erl"},{line,174}]},{amqp_gen_connection,handle_call,3,[{file,"src/amqp_gen_connection.erl"},{line,171}]},{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,580}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]},{<0.230.0>,{amqp_params_network,<<"guest">>,<<"guest">>,<<"/">>,"localhost",5672,0,0,0,infinity,none,[#Fun<amqp_auth_mechanisms.plain.3>,#Fun<amqp_auth_mechanisms.amqplain.3>],[],[]}}],[{file,"src/amqp_gen_connection.erl"},{line,230}]},{gen_server,terminate,6,[{file,"gen_server.erl"},{line,721}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]}

I'm not sure if it's a bug, or if we should be catching the issue in some other way? This code segment is pretty similar to what we have in production:

-module(client).

-include_lib("amqp_client/include/amqp_client.hrl").

-export([test/0]).

test() ->
    case amqp_connection:start(#amqp_params_network{}) of
        {ok, _Connection} -> "SUCCESS";
        {error, _Error} -> "FAILED"
    end.

Looking at the code at amqp_network_connection.erl , line 190, it seems that we are expecting that handshake_recv will only ever reply with a connection.start record, but intermittently our RabbitMQ machine fails at this point and the above error occurs.

Start = #'connection.start'{server_properties = ServerProperties,
                        mechanisms = Mechanisms} =
    handshake_recv('connection.start'),

Could someone please take a look and let me know if this is a bug in the library, or should our application be handling the badmatch condition in some other way?

Thanks

michaelklishin commented 9 years ago

This repository is a mirror. Please post your questions to rabbitmq-users.