Skip to content

Commit 68481b7

Browse files
committed
Do not crash on fake down messages on stream monitor, closes #9803
1 parent e2dc9ae commit 68481b7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/elixir/lib/task/supervised.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ defmodule Task.Supervised do
539539

540540
# One of the spawned processes went down. We inform the parent process of
541541
# this and keep going.
542-
{:DOWN, ref, _, _, reason} ->
542+
{:DOWN, ref, _, _, reason} when is_map_key(running_tasks, ref) ->
543543
{task, running_tasks} = Map.pop(running_tasks, ref)
544544
%{position: position, timer_ref: timer_ref, timed_out?: timed_out?} = task
545545

lib/elixir/test/elixir/task_test.exs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,21 @@ defmodule TaskTest do
584584
[ok: :ok] = Task.async_stream([1], fn _ -> :ok end, timeout: :infinity) |> Enum.to_list()
585585
end
586586

587+
test "streams with fake down messages on the inbox" do
588+
parent = self()
589+
590+
assert Task.async_stream([:ok], fn :ok ->
591+
{:links, links} = Process.info(self(), :links)
592+
593+
for link <- links do
594+
send(link, {:DOWN, make_ref(), :process, parent, :oops})
595+
end
596+
597+
:ok
598+
end)
599+
|> Enum.to_list() == [ok: :ok]
600+
end
601+
587602
test "with $callers" do
588603
grandparent = self()
589604

0 commit comments

Comments
 (0)