Skip to content

Commit 21e43c8

Browse files
author
Matthias Radestock
committed
not_found error on attempt to declare a queue that exists on a stopped node
this prevents loss or duplication of messages when that node recovers I considered returing {ok, Q} | {error, not_found} from internal_declare (and subsequently declare), and let the channel deal with throwing the appropriate amqp error. But - that would be a change to a crucial internal API that is used by quite a few extensions - it would make the return type inconsistent with rabbit_exchange:declare, which too only returns X, not {ok, X}. - the rabbit_amqqueue module already knows about amqp errors - see with_or_die. So this is not breaking any concern separation.
1 parent 21b9b3d commit 21e43c8

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/rabbit_amqqueue.erl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,23 @@ internal_declare(Q = #amqqueue{name = QueueName}, WantDefaultBinding) ->
163163
case rabbit_misc:execute_mnesia_transaction(
164164
fun () ->
165165
case mnesia:wread({rabbit_queue, QueueName}) of
166-
[] -> ok = store_queue(Q),
167-
case WantDefaultBinding of
168-
true -> add_default_binding(Q);
169-
false -> ok
170-
end,
171-
Q;
172-
[ExistingQ] -> ExistingQ
166+
[] ->
167+
case mnesia:read(
168+
{rabbit_durable_queue, QueueName}) of
169+
[] -> ok = store_queue(Q),
170+
case WantDefaultBinding of
171+
true -> add_default_binding(Q);
172+
false -> ok
173+
end,
174+
Q;
175+
[_] -> not_found %% existing Q on stopped node
176+
end;
177+
[ExistingQ] ->
178+
ExistingQ
173179
end
174180
end) of
181+
not_found -> exit(Q#amqqueue.pid, shutdown),
182+
rabbit_misc:not_found(QueueName);
175183
Q -> Q;
176184
ExistingQ -> exit(Q#amqqueue.pid, shutdown),
177185
ExistingQ

0 commit comments

Comments
 (0)