Repository navigation
fix(graphql-server): drop a queued request whose client hung up instead of leaking its concurrency slot - #1924
Open
pyramation wants to merge 1 commit into
Open
pyramation wants to merge 1 commit into
pyramation wants to merge 1 commit into
Conversation
…ad of leaking its concurrency slot The release listeners on the response were attached only after ConcurrencyLimiter.acquire() resolved, so a client that closed the connection while still waiting in the queue was missed: when its turn came it was handed the slot, nothing ever released it, and the per-database budget shrank by one for the life of the process. Watch 'close' from before the wait and pass an AbortSignal into acquire(): an aborted waiter leaves the queue at once (refusal 'aborted') and a grant that races the hang-up is released immediately instead of running the request.
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. No issues found — approved ✅. This PR wires request abort signals into the admission control path: the middleware listens for connection close and aborts queued waiters, and the shared
Reviewed commit: 9648a44 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bug. In
createAdmissionControlMiddleware, theres.on('close')/res.on('finish')listeners that release a concurrency slot were attached only afterawait concurrency.acquire(...)resolved.acquirecan wait up tomaxQueueWaitMsin the queue, so a client that hung up while queued emittedclosebefore any listener existed. When its turn came the dead request was handed the slot,next()ran it against a closed socket, and nothing ever calledlease.release()— the per-database budget shrank by one for the life of the process. Reachable anonymously: a few hundred connect-queue-abort cycles starve the endpoint.Fix.
The existing post-grant
close/finishrelease listeners are unchanged;releasestays idempotent.Tests
admission-control.test.ts— does not leak the slot when the client hangs up while queued: slot held, second request queued, queued response emitsclose, holder finishes; the queued request must not start and a third caller (maxQueueWaitMs: 0) must be admitted immediately.admission.test.ts(ConcurrencyLimiter) — an aborted waiter leaves the queue with refusal'aborted'and the next arrival gets the slot; a pre-aborted signal is refused without queueing.Before (main + these tests):
After:
admission-control.test.ts18 passed,admission.test.ts28 passed; eslint clean on the four touched files.Link to Devin session: https://app.devin.ai/sessions/959661f0d69640789bd6b38550d379b7
Open in Devin Desktop: https://app.devin.ai/desktop/session/959661f0d69640789bd6b38550d379b7?variant=devin
Requested by: @pyramation