From 40957a2c628f633c8432375ca00c5ff27e0bde3c Mon Sep 17 00:00:00 2001 From: Simon MacMullen Date: Mon, 9 Sep 2013 11:53:12 +0100 Subject: Introduce a new return code for this case, since {new, Q} is going to mess up recovery by claiming we recovered something we didn't. Also {existing, Q} would make the channel enter an infinite loop, and {absent, Q} would return an AMQP NOT_FOUND which might be bewildering to the client if it managed to receive it. So we need a fourth possibility. --- src/rabbit_amqqueue.erl | 4 ++-- src/rabbit_amqqueue_process.erl | 6 +----- src/rabbit_channel.erl | 7 ++++++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index a1efaf65..32feac30 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -72,8 +72,8 @@ -spec(declare/5 :: (name(), boolean(), boolean(), rabbit_framing:amqp_table(), rabbit_types:maybe(pid())) - -> {'new' | 'existing' | 'absent', rabbit_types:amqqueue()} | - rabbit_types:channel_exit()). + -> {'new' | 'existing' | 'absent' | 'owner_died', + rabbit_types:amqqueue()} | rabbit_types:channel_exit()). -spec(internal_declare/2 :: (rabbit_types:amqqueue(), boolean()) -> queue_or_absent() | rabbit_misc:thunk(queue_or_absent())). diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl index cd56f098..ac19461c 100644 --- a/src/rabbit_amqqueue_process.erl +++ b/src/rabbit_amqqueue_process.erl @@ -1070,11 +1070,7 @@ handle_call({init, Recover}, From, false -> #q{backing_queue = undefined, backing_queue_state = undefined, q = #amqqueue{name = QName} = Q} = State, - %% If the connection has died then what we reply is somewhat - %% moot. But it seems reasonable to act as though the queue - %% was declared and then the connection died - we're only a - %% small timing difference away from that case anyway. - gen_server2:reply(From, {new, Q}), + gen_server2:reply(From, {owner_died, Q}), case Recover of new -> rabbit_log:warning( "exclusive owner for ~s went away~n", diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index d6c1e8c0..4a194047 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -1021,7 +1021,12 @@ handle_method(#'queue.declare'{queue = QueueNameBin, %% declare. Loop around again. handle_method(Declare, none, State); {absent, Q} -> - rabbit_misc:absent(Q) + rabbit_misc:absent(Q); + {owner_died, Q} -> + %% Presumably our own days are numbered since the + %% connection has died. Pretend the queue exists though, + %% just so nothing fails. + return_queue_declare_ok(QueueName, NoWait, 0, 0, State) end; {error, {absent, Q}} -> rabbit_misc:absent(Q) -- cgit v1.2.1