Skip to content

Commit c2ea628

Browse files
committed
fix exchange deletion logic
It seems deletion requests come duplicated, worth asking RabbitMQ if it's intended behaviour. Signed-off-by: Matteo Cafasso <[email protected]>
1 parent bc56111 commit c2ea628

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/cache.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ defmodule RabbitMQ.Cache do
4949
GenServer.call(cache, {:drop, cache})
5050
end
5151

52+
@doc """
53+
Return the PID of the given cache, nil if non existing.
54+
"""
55+
def process(cache) do
56+
GenServer.whereis(cache)
57+
end
58+
5259
## Server Callbacks
5360

5461
def init({cache, options}) do
@@ -97,7 +104,10 @@ defmodule RabbitMQ.Cache do
97104
end
98105

99106
def handle_call({:drop, cache}, _from, state) do
100-
{:reply, Mnesia.delete_table(cache), state}
107+
case Mnesia.delete_table(cache) do
108+
{:atomic, :ok} -> {:reply, :ok, state}
109+
_ -> {:reply, :error, state}
110+
end
101111
end
102112

103113
## Utility functions

lib/rabbit_message_deduplication_exchange.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,13 @@ defmodule RabbitMQ.ExchangeTypeMessageDeduplication do
112112
def delete(_tx, exchange(name: name), _bs) do
113113
cache = cache_name(name)
114114

115-
{_, :ok} = RabbitMQ.Cache.drop(cache)
116-
:ok = RabbitMQ.Supervisor.terminate_child(cache)
115+
# It seems the deletion request comes duplicated
116+
case RabbitMQ.Cache.process(cache) do
117+
pid when is_pid(pid) ->
118+
:ok = RabbitMQ.Cache.drop(cache)
119+
RabbitMQ.Supervisor.terminate_child(pid)
120+
nil -> :ok
121+
end
117122
end
118123

119124
def policy_changed(_x1, _x2) do

0 commit comments

Comments
 (0)