quic: destroy stream on invalid promise body - #66260
Open
christianaurichzm wants to merge 1 commit into
Open
christianaurichzm wants to merge 1 commit into
christianaurichzm wants to merge 1 commit into
Conversation
When `setBody()` receives a promise that resolves to an unsupported body type, `configureOutbound()` throws inside the fulfillment handler. The rejection handler only covered the original promise, so the error rejected a discarded promise and crashed the process as an unhandled rejection. Chain the rejection handler after the fulfillment handler so both cases destroy the stream with the error. For an unsupported resolved value, `stream.closed` now rejects with the same `ERR_INVALID_ARG_TYPE` that `setBody()` throws synchronously. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66260 +/- ##
==========================================
- Coverage 90.30% 90.28% -0.03%
==========================================
Files 789 789
Lines 272880 272883 +3
Branches 52106 52107 +1
==========================================
- Hits 246423 246369 -54
- Misses 16918 16976 +58
+ Partials 9539 9538 -1
🚀 New features to boost your workflow:
|
pimterry
approved these changes
Sep 25, 2026
pimterry
left a comment
Member
There was a problem hiding this comment.
Thanks @christianaurichzm! Good find, fix LGTM.
Would be nice to avoid the extra Then step imo, but I don't feel strongly.
| body, | ||
| (resolved) => configureOutbound(handle, stream, resolved), | ||
| ), | ||
| undefined, |
Member
There was a problem hiding this comment.
Nit: this adds another promise layer, which adds a microtask step and a small perf cost on every request, and we're only trying to catch sync errors so that layer's not really necessary.
Could we rewrite to use a try/catch inside the fulfilment step instead?
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.
stream.setBody(Promise.resolve(42))crashes the process with an unhandled rejection, whilestream.setBody(42)throwsERR_INVALID_ARG_TYPEsynchronously.configureOutbound()calls itself with the resolved value inside the fulfillment handler ofPromisePrototypeThen(). The rejection handler only coversbodyitself rejecting, so when that call throws, the error goes to the promise returned byPromisePrototypeThen(), which nothing handles.This moves the rejection handler to a second
PromisePrototypeThen(), so it catches both cases and destroys the stream with the error. The same goes forERR_INVALID_STATEwhen the promise resolves to aFileHandlealready in use by another stream. A rejectedbodynow destroys the stream one microtask later.On
mainthe new test crashes. With this change alltest/parallel/test-quic-*.mjstests pass andmake lintis clean.