Release the parallelism slot when a dispatched message rejects - #1857
Open
Ngo Quoc Viet (NgoQuocViet2001) wants to merge 1 commit into
Open
Ngo Quoc Viet (NgoQuocViet2001) wants to merge 1 commit into
Ngo Quoc Viet (NgoQuocViet2001) wants to merge 1 commit into
Conversation
With maxParallelism set, the message queue's bookkeeping lived only in the fulfilment callback of .then(...).catch(...). A rejected dispatch skipped inFlight-- and the re-pump, so one failure left inFlight permanently at the limit and triggerMessageQueue() returned early from then on: the connection stayed open and Listening while every later request and notification sat in the queue undelivered. Use the two-argument form of then so both settlements decrement and re-pump.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
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.
Problem
With
maxParallelismconfigured, the message queue's slot accounting lives only in the fulfilment callback:Written as
.then(onFulfilled).catch(onRejected), a rejection skipsonFulfilledentirely. The.catchlogs, but never runsinFlight--and never re-pumps.inFlightis the gatetriggerMessageQueuechecks:so one rejected dispatch leaves the counter permanently at the limit and the queue stops draining. The connection stays open and
Listening; there is no error event, no close, nothing but a single log line, while every later request and notification sits inmessageQueueforever.Trigger
The promise the queue awaits is
handleRequest's, which ends inmessageWriter.write(...). A response that cannot be serialized rejects it. A handler throwing aResponseErrorwhosedatais not JSON-serializable is enough —toJson()copiesdataonto the wire message:With
{ maxParallelism: 1 }, the request after it is never answered.A handler that merely throws is not affected — that is caught inside
handleRequestand turned into a well-formedreplyError. It is the failure to write the response that escapes.Fix
Use the two-argument form of
then, so both settlements do the same bookkeeping. The log line is unchanged.The
maxParallelism === -1default never reaches the gate, so unlimited-parallelism behaviour is untouched.Test plan
Parallelism - a rejected dispatch releases its slottojsonrpc/src/node/test/connection.test.ts, beside the existingParallelism - limitedcase and reusing itsTestDuplexpair.npm run compile:jsonrpcthen the node suite fromjsonrpc/→ 68 passing.connection.tsfails the new test with'timed out'— the second request is never answered.npx eslint srcinjsonrpc/→ clean.