From 095897e04f445e6d397c5197bb5a7d3d37dec8d6 Mon Sep 17 00:00:00 2001 From: kjnilsson Date: Tue, 2 May 2017 12:05:13 +0100 Subject: [PATCH] Treat unexpected socket closures as errors. AMQP 1.0 requires connection closure to follow protocol. Hence we treat unexpected socket closures as errors and avoid trying to terminate the supervisor as this can cause a race condition when the connection tries to do the same. --- .../src/amqp10_client_frame_reader.erl | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/deps/amqp10_client/src/amqp10_client_frame_reader.erl b/deps/amqp10_client/src/amqp10_client_frame_reader.erl index 1298ec162c..19c9f546f9 100644 --- a/deps/amqp10_client/src/amqp10_client_frame_reader.erl +++ b/deps/amqp10_client/src/amqp10_client_frame_reader.erl @@ -177,7 +177,7 @@ handle_info({TcpClosed, _}, StateName, State) State1 = State#state{socket = undefined, buffer = <<>>, frame_state = undefined}, - {stop, normal, State1}; + {stop, {error, TcpClosed}, State1}; handle_info(heartbeat, StateName, State = #state{connection = Conn}) -> amqp10_client_connection:close(Conn, {resource_limit_exceeded, @@ -185,19 +185,12 @@ handle_info(heartbeat, StateName, State = #state{connection = Conn}) -> % do not stop as may want to read the peer's close frame {next_state, StateName, State}. -terminate(Reason, _StateName, #state{connection_sup = Sup, socket = Socket}) -> +terminate(Reason, _StateName, #state{connection_sup = _Sup, socket = Socket}) -> error_logger:warning_msg("terminating reader with '~p'~n", [Reason]), case Socket of undefined -> ok; _ -> close_socket(Socket) - end, - case Reason of - normal -> - error_logger:warning_msg("terminating sup from reader with~n", []), - sys:terminate(Sup, normal); - _ -> ok - end, - ok. + end. code_change(_OldVsn, StateName, State, _Extra) -> {ok, StateName, State}.