Skip to content

Wake queued callers after cancelling a pool holder - #54

Merged
josevalim merged 1 commit into
dashbitco:mainfrom
evadne:feature/wake-cancelled-pool-waiters
Sep 7, 2026
Merged

josevalim merged 1 commit into
dashbitco:mainfrom
evadne:feature/wake-cancelled-pool-waiters

Conversation

@evadne

@evadne evadne commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

After a normal borrower crash, queued callers can remain blocked despite available capacity and no active borrower. Progress depends on unrelated future activity, so with an infinite checkout timeout, the wait can be indefinite.

Reproduction

Using a lazy pool, size 1:

  1. Caller A checks out the resource.
  2. Caller B queues behind A.
  3. A dies, or exits inside the checkout callback.
  4. Cancellation handling removes A’s request and resource, restoring lazy capacity

Cancellation returns without attempting to serve B.

Expected Behaviour

Cancellation results in B being served in a timely manner.

Discussion

In eager mode, removing the resource schedules an initialisation message that allows the queue to progress. Lazy mode does not schedule that message, so the existing waiter can remain stranded until another event advances the queue.

This change calls the existing maybe_checkout/1 after removing the cancelled caller's resource. It reuses the normal queue, deadline and lazy-initialisation handling. The failed resource is discarded; it is not checked back in or reused.

Testing

The four regression cases produce two failures on both v1.1.0 and upstream main; both lazy cases fail, both eager controls pass. With this change, all four cases pass. The full patched suite passes on Elixir 1.19.2 and Erlang/OTP 28.1.1.

Commentary

It is unclear whether this is expected behaviour. If it is, please feel free to close the PR.

Reconsider pending checkouts after removing a cancelled holder so lazy pools restore progress without another arrival. Cover caller death and callback exit in lazy and eager pools.

Await the asynchronous idle-worker termination notification in the existing test. Validate this fork with local mix test.
@josevalim
josevalim merged commit 23326be into dashbitco:main Sep 7, 2026
0 of 2 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants