test: fix flaky test-http2-close-while-writing#61804
Open
Han5991 wants to merge 1 commit intonodejs:mainfrom
Open
test: fix flaky test-http2-close-while-writing#61804Han5991 wants to merge 1 commit intonodejs:mainfrom
Han5991 wants to merge 1 commit intonodejs:mainfrom
Conversation
The test was flaky due to a race condition where `client.close()` would wait for a graceful shutdown while the server had already destroyed the session/stream, leading to a timeout. Changes: - Replace `client.close()` with `client.destroy()` in the `close` event handler of the client stream. - Add `common.mustNotCall()` error handlers to the client, client stream, and server session to catch unexpected errors. - Add check `if (!client_stream.destroyed)` before destroying client stream in the server's data handler. Refs: nodejs#33156
lpinca
reviewed
Feb 13, 2026
| let client_stream; | ||
|
|
||
| server.on('session', common.mustCall(function(session) { | ||
| session.on('error', common.mustNotCall()); |
Member
There was a problem hiding this comment.
Suggested change
| session.on('error', common.mustNotCall()); |
This is already covered by the default behavior of unhandled 'error' events.
Comment on lines
+30
to
+34
| process.nextTick(() => { | ||
| if (!client_stream.destroyed) { | ||
| client_stream.destroy(); | ||
| } | ||
| }); |
Member
There was a problem hiding this comment.
Suggested change
| process.nextTick(() => { | |
| if (!client_stream.destroyed) { | |
| client_stream.destroy(); | |
| } | |
| }); | |
| process.nextTick(() => client_stream.destroy()); |
This is already done in the stream.destroy() implementation.
| ca, | ||
| maxSessionMemory: 1000 | ||
| }); | ||
| client.on('error', common.mustNotCall()); |
Member
There was a problem hiding this comment.
Suggested change
| client.on('error', common.mustNotCall()); |
| }); | ||
| client.on('error', common.mustNotCall()); | ||
| client_stream = client.request({ ':method': 'POST' }); | ||
| client_stream.on('error', common.mustNotCall()); |
Member
There was a problem hiding this comment.
Suggested change
| client_stream.on('error', common.mustNotCall()); |
| client_stream.on('error', common.mustNotCall()); | ||
| client_stream.on('close', common.mustCall(() => { | ||
| client.close(); | ||
| client.destroy(); |
Member
There was a problem hiding this comment.
It is still not clear to me why this callback
node/lib/internal/http2/core.js
Lines 2192 to 2196 in 6710c00
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61804 +/- ##
==========================================
+ Coverage 89.75% 89.76% +0.01%
==========================================
Files 675 675
Lines 204676 204731 +55
Branches 39329 39343 +14
==========================================
+ Hits 183705 183779 +74
+ Misses 13272 13238 -34
- Partials 7699 7714 +15 🚀 New features to boost your workflow:
|
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.
The test was flaky due to a race condition where
client.close()wouldwait for a graceful shutdown while the server had already destroyed the
session/stream, leading to a timeout.
Changes:
client.close()withclient.destroy()in thecloseeventhandler of the client stream.
common.mustNotCall()error handlers to the client, client stream,and server session to catch unexpected errors.
if (!client_stream.destroyed)before destroying clientstream in the server's data handler.
Refs: #33156