Skip to content

Commit 20621d4

Browse files
author
José Valim
committed
Do not leak EXIT messages on Registry dispatch
Signed-off-by: José Valim <[email protected]>
1 parent 600ca02 commit 20621d4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/elixir/lib/registry.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,13 @@ defmodule Registry do
359359
end
360360
defp dispatch_task(registry, key, mfa_or_fun, partition) do
361361
partition = partition - 1
362+
parent = self()
362363
task = Task.async(fn ->
363364
registry
364365
|> key_ets!(partition)
365366
|> safe_lookup_second(key)
366367
|> apply_non_empty_to_mfa_or_fun(mfa_or_fun)
368+
Process.unlink(parent)
367369
:ok
368370
end)
369371
[task | dispatch_task(registry, key, mfa_or_fun, partition)]

lib/elixir/test/elixir/registry_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ defmodule RegistryTest do
207207
end
208208

209209
test "dispatches to multiple keys", %{registry: registry} do
210+
Process.flag(:trap_exit, true)
211+
210212
assert Registry.dispatch(registry, "hello", fn _ ->
211213
raise "will never be invoked"
212214
end) == :ok
@@ -230,6 +232,8 @@ defmodule RegistryTest do
230232
refute_received {:dispatch, :value1}
231233
refute_received {:dispatch, :value2}
232234
assert_received {:dispatch, :value3}
235+
236+
refute_received {:EXIT, _, _}
233237
end
234238

235239
test "allows process unregistering", %{registry: registry} do

0 commit comments

Comments
 (0)