Repository navigation
quic: truncate CONNECTION_CLOSE frame reason field #66644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nodejs-github-bot
merged 4 commits into
nodejs:main
from
efekrskl:quic/truncate-close-reason
Oct 20, 2026
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
112 changes: 112 additions & 0 deletions
112
test/parallel/test-quic-session-close-reason-truncation.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // Flags: --experimental-quic --no-warnings | ||
|
|
||
| // CONNECTION_CLOSE reason strings are truncated to 256 UTF-8 bytes. | ||
|
|
||
| import { hasQuic, skip, mustCall } from '../common/index.mjs'; | ||
| import assert from 'node:assert'; | ||
| import { setTimeout } from 'node:timers/promises'; | ||
|
|
||
| if (!hasQuic) { | ||
| skip('QUIC is not enabled'); | ||
| } | ||
|
|
||
| const { listen, connect } = await import('../common/quic.mjs'); | ||
|
|
||
| const kMaxReasonLength = 256; | ||
|
|
||
| // Client close with an ASCII reason longer than the wire limit. | ||
| { | ||
| const reason = 'a'.repeat(kMaxReasonLength + 1); | ||
| const expectedReason = reason.slice(0, kMaxReasonLength); | ||
| const serverDone = Promise.withResolvers(); | ||
|
|
||
| const serverEndpoint = await listen(mustCall(async (serverSession) => { | ||
| serverSession.onerror = mustCall((error) => { | ||
| assert.strictEqual(error.reason, expectedReason); | ||
| }); | ||
| await assert.rejects(serverSession.closed, { | ||
| code: 'ERR_QUIC_APPLICATION_ERROR', | ||
| reason: expectedReason, | ||
| }); | ||
| serverDone.resolve(); | ||
| })); | ||
|
|
||
| const clientSession = await connect(serverEndpoint.address, { | ||
| reuseEndpoint: false, | ||
| }); | ||
| await clientSession.opened; | ||
| await setTimeout(100); | ||
| await clientSession.close({ | ||
| code: 1n, | ||
| type: 'application', | ||
| reason, | ||
| }); | ||
|
|
||
| await serverDone.promise; | ||
| await serverEndpoint.close(); | ||
| } | ||
|
|
||
| // Client close where truncating at the byte limit would split a UTF-8 sequence. | ||
| { | ||
| const prefix = 'a'.repeat(kMaxReasonLength - 1); | ||
| const reason = `${prefix}€`; | ||
| const serverDone = Promise.withResolvers(); | ||
|
|
||
| const serverEndpoint = await listen(mustCall(async (serverSession) => { | ||
| serverSession.onerror = mustCall((error) => { | ||
| assert.strictEqual(error.reason, prefix); | ||
| }); | ||
| await assert.rejects(serverSession.closed, { | ||
| code: 'ERR_QUIC_APPLICATION_ERROR', | ||
| reason: prefix, | ||
| }); | ||
| serverDone.resolve(); | ||
| })); | ||
|
|
||
| const clientSession = await connect(serverEndpoint.address, { | ||
| reuseEndpoint: false, | ||
| }); | ||
| await clientSession.opened; | ||
| await setTimeout(100); | ||
| await clientSession.close({ | ||
| code: 2n, | ||
| type: 'application', | ||
| reason, | ||
| }); | ||
|
|
||
| await serverDone.promise; | ||
| await serverEndpoint.close(); | ||
| } | ||
|
|
||
| // Server close exercises the server-specific CONNECTION_CLOSE packet path. | ||
| { | ||
| const reason = 's'.repeat(kMaxReasonLength + 1); | ||
| const expectedReason = reason.slice(0, kMaxReasonLength); | ||
| const serverDone = Promise.withResolvers(); | ||
|
|
||
| const serverEndpoint = await listen(mustCall(async (serverSession) => { | ||
| await serverSession.opened; | ||
| await setTimeout(100); | ||
| await serverSession.close({ | ||
| code: 3n, | ||
| type: 'application', | ||
| reason, | ||
| }); | ||
| serverDone.resolve(); | ||
| })); | ||
|
|
||
| const clientSession = await connect(serverEndpoint.address, { | ||
| reuseEndpoint: false, | ||
| onerror: mustCall((error) => { | ||
| assert.strictEqual(error.reason, expectedReason); | ||
| }), | ||
| }); | ||
| await clientSession.opened; | ||
| await assert.rejects(clientSession.closed, { | ||
| code: 'ERR_QUIC_APPLICATION_ERROR', | ||
| reason: expectedReason, | ||
| }); | ||
|
|
||
| await serverDone.promise; | ||
| await serverEndpoint.close(); | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.