Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
always clean up on channel process termination.
Browse files Browse the repository at this point in the history
Refactored the code so that this is more obvious, and thus caught the
one (?) place where it wasn't happenig - handling of channel.close_ok.
  • Loading branch information
Matthias Radestock committed Apr 10, 2009
1 parent e41b0d3 commit 25f2a9e
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/amqp_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ rpc_bottom_half(#'channel.close'{reply_code = ReplyCode,
reply_text = ReplyText}, State) ->
io:format("Channel received close from peer, code: ~p , message: ~p~n",
[ReplyCode,ReplyText]),
NewState = channel_cleanup(State),
{stop, normal, NewState};
{stop, normal, State};

rpc_bottom_half(Reply, State = #channel_state{writer_pid = Writer,
rpc_requests = RequestQueue,
Expand Down Expand Up @@ -379,8 +378,7 @@ handle_info( {send_command_and_notify, Q, ChPid, Method, Content}, State) ->
{noreply, State};

handle_info(shutdown, State) ->
NewState = channel_cleanup(State),
{stop, normal, NewState};
{stop, normal, State};

%% Handle a trapped exit, e.g. from the direct peer
%% In the direct case this is the local channel
Expand All @@ -389,8 +387,7 @@ handle_info(shutdown, State) ->
handle_info({'EXIT', _Pid, Reason},
State = #channel_state{number = Number}) ->
io:format("Channel ~p is shutting down due to: ~p~n",[Number, Reason]),
NewState = channel_cleanup(State),
{stop, normal, NewState};
{stop, normal, State};

%% This is for a race condition between a close.close_ok and a subsequent
%% channel.open
Expand All @@ -403,16 +400,12 @@ handle_info( {channel_close, Peer}, State ) ->
%% This is for a channel exception that can't be otherwise handled
handle_info( {channel_exception, Channel, Reason}, State) ->
io:format("Channel ~p is shutting down due to: ~p~n",[Channel, Reason]),
NewState = channel_cleanup(State),
{stop, shutdown, NewState}.
{stop, shutdown, State}.

%%---------------------------------------------------------------------------
%% Rest of the gen_server callbacks
%%---------------------------------------------------------------------------

terminate(normal, _State) ->
ok;

terminate(_Reason, State) ->
channel_cleanup(State),
ok.
Expand Down

0 comments on commit 25f2a9e

Please sign in to comment.