Skip to content

Commit 0b5dc9d

Browse files
ansdmergify[bot]
authored andcommitted
amqp10_client: Fix crash in close_sent
Fix crash in close_sent since the client might receive the open frame if it previously sent the close frame in state open_sent. We explicitly ignore the open frame. The alternative is to add another gen_statem state CLOSE_PIPE which might be an overkill however. This commit also fixes a wrong comment: No sessions have begun if the app requests the connection to be closed in state open_sent. (cherry picked from commit 6557686) # Conflicts: # deps/amqp10_client/src/amqp10_client_connection.erl
1 parent ae405e2 commit 0b5dc9d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

deps/amqp10_client/src/amqp10_client_connection.erl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ open_sent({call, From}, begin_session,
288288
open_sent(info, {'DOWN', MRef, _, _, _},
289289
=======
290290
open_sent(_EvtType, {close, Reason}, State) ->
291-
%% TODO: stop all sessions writing
292-
%% We could still accept incoming frames (See: 2.4.6)
293291
case send_close(State, Reason) of
294292
ok ->
295293
%% "After writing this frame the peer SHOULD continue to read from the connection
@@ -344,6 +342,7 @@ close_sent(_EvtType, heartbeat, State) ->
344342
{next_state, close_sent, State};
345343
close_sent(_EvtType, {'EXIT', _Pid, shutdown}, State) ->
346344
%% monitored processes may exit during closure
345+
<<<<<<< HEAD
347346
{next_state, close_sent, State};
348347
close_sent(_EvtType, {'DOWN', _Ref, process, ReaderPid, _},
349348
#state{reader = ReaderPid} = State) ->
@@ -353,6 +352,21 @@ close_sent(_EvtType, #'v1_0.close'{}, State) ->
353352
%% TODO: we should probably set up a timer before this to ensure
354353
%% we close down event if no reply is received
355354
{stop, normal, State}.
355+
=======
356+
keep_state_and_data;
357+
close_sent(_EvtType, {'DOWN', _Ref, process, ReaderPid, _Reason},
358+
#state{reader = ReaderPid}) ->
359+
%% if the reader exits we probably won't receive a close frame
360+
{stop, normal};
361+
close_sent(_EvtType, #'v1_0.close'{} = Close, #state{config = Config}) ->
362+
ok = notify_closed(Config, Close),
363+
{stop, normal};
364+
close_sent(state_timeout, received_no_close_frame, _Data) ->
365+
{stop, normal};
366+
close_sent(_EvtType, #'v1_0.open'{}, _Data) ->
367+
%% Transition from CLOSE_PIPE to CLOSE_SENT in figure 2.23.
368+
keep_state_and_data.
369+
>>>>>>> 65576863f (amqp10_client: Fix crash in close_sent)
356370

357371
set_other_procs0(OtherProcs, State) ->
358372
#{sessions_sup := SessionsSup,

0 commit comments

Comments
 (0)