Fix unhandled rejection when writing a JSON-RPC request fails - #1855
Open
Heejae Chang (heejaechang) wants to merge 1 commit into
Open
Heejae Chang (heejaechang) wants to merge 1 commit into
Heejae Chang (heejaechang) wants to merge 1 commit into
Conversation
Remove the redundant throw after rejecting the request promise. Add a strict subprocess regression covering a destroyed stream, the caller error, error reporting, and request cancellation cleanup. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
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.
Summary
When a peer exits or a transport closes while a request is being written,
sendRequestrejects the caller-visible promise withResponseError(ErrorCodes.MessageWriteError, ...). Its catch block then rethrows the original writer error from an async Promise executor. The Promise constructor ignores that executor's returned promise, so the rethrow creates a second, unhandled rejection even when the caller correctly handles the request failure. This can fail tests or terminate a host process.Remove only the redundant rethrow. The original request rejection and error message, pending-response removal, cancellation cleanup, and logging are preserved.
Regression coverage
Add a deterministic Node test using
createMessageConnectionand a destroyedPassThroughstream. A child process runs with--unhandled-rejections=strict, explicitly handles the request rejection, and exits naturally. This isolates rejection handling from Mocha without suppressing unhandled rejections or using sleeps. The test also checks transport error reporting, logging, pending-response removal, cancellation cleanup, and cancellation-listener disposal.Validation
ERR_STREAM_DESTROYED.npm run compile:jsonrpcnpm run test:node --prefix jsonrpc -- --grep "Request write failure does not cause an unhandled rejection|Handle Single Request|Handle Multiple Requests|Cancellation|cancel|dispose"npm run lint --prefix jsonrpcValidated on Windows with Node.js 24.15.0. A full root dependency restore was blocked by an unavailable package in the local package mirror; focused validation used the repository's exact direct compiler/test/lint tool versions without modifying repository manifests or lockfiles. Browser runtime tests were not run.