Skip to content

quic: destroy stream on invalid promise body - #66260

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
christianaurichzm:quic-promise-body-invalid
Oct 6, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
christianaurichzm:quic-promise-body-invalid

Conversation

@christianaurichzm

@christianaurichzm christianaurichzm commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

stream.setBody(Promise.resolve(42)) crashes the process with an unhandled rejection, while stream.setBody(42) throws ERR_INVALID_ARG_TYPE synchronously.

const stream = await clientSession.createBidirectionalStream();
stream.setBody(Promise.resolve(42));

configureOutbound() calls itself with the resolved value inside the fulfillment handler of PromisePrototypeThen(). The rejection handler only covers body itself rejecting, so when that call throws, the error goes to the promise returned by PromisePrototypeThen(), which nothing handles.

This wraps that call in a try/catch and destroys the stream with the error, the same way the rejection handler already does. The same goes for ERR_INVALID_STATE when the promise resolves to a FileHandle already in use by another stream. Nothing changes for a body that rejects.

On main the new test crashes. With this change all test/parallel/test-quic-*.mjs tests pass and make lint is clean.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/quic

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. quic Issues and PRs related to the QUIC transport implementation. labels Sep 24, 2026
@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.37%. Comparing base (24b9ca9) to head (413eb7d).
⚠️ Report is 306 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66260      +/-   ##
==========================================
+ Coverage   90.30%   90.37%   +0.06%     
==========================================
  Files         789      790       +1     
  Lines      272880   273847     +967     
  Branches    52106    52382     +276     
==========================================
+ Hits       246423   247477    +1054     
+ Misses      16918    16858      -60     
+ Partials     9539     9512      -27     
Files with missing lines Coverage Δ
lib/internal/quic/quic.js 100.00% <100.00%> (ø)

... and 84 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pimterry pimterry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @christianaurichzm! Good find, fix LGTM.

Would be nice to avoid the extra Then step imo, but I don't feel strongly.

Comment thread lib/internal/quic/quic.js Outdated
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.

Catch errors thrown by `configureOutbound()` in the fulfillment
handler and destroy the stream with them, as the rejection handler
already does. 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>
@pimterry pimterry added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 5, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 5, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@pimterry pimterry added the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 6, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 8314231 into nodejs:main Oct 6, 2026
78 of 79 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 8314231

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. quic Issues and PRs related to the QUIC transport implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants