summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@rabbitmq.com>2011-02-10 16:30:55 +0000
committerMatthew Sackman <matthew@rabbitmq.com>2011-02-10 16:30:55 +0000
commit41ddcdf2ee8b174bd5ad3a621e83080e71b0c8f0 (patch)
treede137a65ca40b59bdadecd9e8be4843f384d8a77 /src
parent20bfae49c046cc3978a46b2de9faabe6241ce97f (diff)
downloadrabbitmq-server-git-41ddcdf2ee8b174bd5ad3a621e83080e71b0c8f0.tar.gz
server initiated channel.close: keep channel alive until ch.close_ok is received. Make channel responsible for deciding on the severity of the error
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_channel.erl25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl
index 1903ff429b..9da29b378e 100644
--- a/src/rabbit_channel.erl
+++ b/src/rabbit_channel.erl
@@ -219,12 +219,13 @@ handle_cast({method, Method, Content}, State) ->
ok = rabbit_writer:send_command(NewState#ch.writer_pid, Reply),
noreply(NewState);
{noreply, NewState} ->
- noreply(NewState)
+ noreply(NewState);
+ stop ->
+ {stop, normal, State}
catch
exit:Reason = #amqp_error{} ->
MethodName = rabbit_misc:method_record_type(Method),
- {stop, normal, terminating(Reason#amqp_error{method = MethodName},
- State)};
+ send_exception(Reason#amqp_error{method = MethodName}, State);
_:Reason ->
{stop, {Reason, erlang:get_stacktrace()}, State}
end;
@@ -359,6 +360,21 @@ terminating(Reason, State = #ch{channel = Channel, reader_pid = Reader}) ->
Reader ! {channel_exit, Channel, Reason},
State#ch{state = terminating}.
+send_exception(Reason, State = #ch{channel = Channel,
+ writer_pid = WriterPid,
+ protocol = Protocol,
+ reader_pid = ReaderPid}) ->
+ {_ShouldClose, CloseChannel, CloseMethod} =
+ rabbit_binary_generator:map_exception(Channel, Reason, Protocol),
+ case CloseChannel of
+ Channel ->
+ ok = rabbit_writer:send_command(WriterPid, CloseMethod),
+ {noreply, State#ch{state = closing}};
+ _ ->
+ ReaderPid ! {channel_exit, Channel, Reason},
+ {stop, normal, State}
+ end.
+
return_queue_declare_ok(#resource{name = ActualName},
NoWait, MessageCount, ConsumerCount, State) ->
return_ok(State#ch{most_recently_declared_queue = ActualName}, NoWait,
@@ -529,6 +545,9 @@ handle_method(#'channel.open'{}, _, _State) ->
handle_method(_Method, _, #ch{state = starting}) ->
rabbit_misc:protocol_error(channel_error, "expected 'channel.open'", []);
+handle_method(#'channel.close_ok'{}, _, #ch{state = closing}) ->
+ stop;
+
handle_method(_Method, _, State = #ch{state = closing}) ->
{noreply, State};