Skip to content

Commit fe3c393

Browse files
aerosoljosevalim
authored andcommitted
Disallow streaming with max_concurrency=0 (#10966)
1 parent d9d7015 commit fe3c393

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/elixir/lib/task/supervised.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ defmodule Task.Supervised do
177177
def stream(enumerable, acc, reducer, mfa, options, spawn) do
178178
next = &Enumerable.reduce(enumerable, &1, fn x, acc -> {:suspend, [x | acc]} end)
179179
max_concurrency = Keyword.get(options, :max_concurrency, System.schedulers_online())
180+
181+
unless is_integer(max_concurrency) and max_concurrency > 0 do
182+
raise ArgumentError, ":max_concurrency must be an integer greater than zero"
183+
end
184+
180185
ordered? = Keyword.get(options, :ordered, true)
181186
timeout = Keyword.get(options, :timeout, 5000)
182187
on_timeout = Keyword.get(options, :on_timeout, :exit)

lib/elixir/test/elixir/task_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,12 @@ defmodule TaskTest do
717717
[ok: :ok] = Task.async_stream([1], fn _ -> :ok end, timeout: :infinity) |> Enum.to_list()
718718
end
719719

720+
test "does not allow streaming with max_concurrency = 0" do
721+
assert_raise ArgumentError, ":max_concurrency must be an integer greater than zero", fn ->
722+
Task.async_stream([1], fn _ -> :ok end, max_concurrency: 0) |> Enum.to_list()
723+
end
724+
end
725+
720726
test "streams with fake down messages on the inbox" do
721727
parent = self()
722728

0 commit comments

Comments
 (0)