Skip to content

Fix Task.yield_many/2 waits too long or forever when :limit exceeds task count - #15737

Merged
josevalim merged 2 commits into
elixir-lang:mainfrom
AlexGx:ag-task_yield_many_limit-fix
Aug 12, 2026
Merged

Fix Task.yield_many/2 waits too long or forever when :limit exceeds task count#15737
josevalim merged 2 commits into
elixir-lang:mainfrom
AlexGx:ag-task_yield_many_limit-fix

Conversation

@AlexGx

@AlexGx AlexGx commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Task.yield_many/2 waits until timeout/forever when :limit exceeds number of unique tasks.

Examples:

task = Task.completed(:ok)

Task.yield_many(
  [task, task],
  limit: 2,
  timeout: :infinity
)
# waits forever, unique task count is lower than limit
task = Task.async(fn -> :done end)

Task.yield_many(
  [task],
  limit: 2,
  timeout: 15_000
)
# waits 15 secs, instead of returning immediately

The fix is to clamp limit to the number of unique task refs so the function returns as soon as all tasks have been completed.

Comment thread lib/elixir/test/elixir/task_test.exs Outdated
@josevalim
josevalim merged commit 7bf6518 into elixir-lang:main Aug 12, 2026
15 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@AlexGx
AlexGx deleted the ag-task_yield_many_limit-fix branch August 12, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants