Skip to content

test: fix flaky test-http2-close-while-writing#61804

Open
Han5991 wants to merge 1 commit intonodejs:mainfrom
Han5991:test/fix-flaky-http2-close-while-writing
Open

test: fix flaky test-http2-close-while-writing#61804
Han5991 wants to merge 1 commit intonodejs:mainfrom
Han5991:test/fix-flaky-http2-close-while-writing

Conversation

@Han5991
Copy link
Contributor

@Han5991 Han5991 commented Feb 13, 2026

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: #33156

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
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Feb 13, 2026
let client_stream;

server.on('session', common.mustCall(function(session) {
session.on('error', common.mustNotCall());
Copy link
Member

Choose a reason for hiding this comment

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

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();
}
});
Copy link
Member

Choose a reason for hiding this comment

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

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());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
client.on('error', common.mustNotCall());

});
client.on('error', common.mustNotCall());
client_stream = client.request({ ':method': 'POST' });
client_stream.on('error', common.mustNotCall());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
client_stream.on('error', common.mustNotCall());

client_stream.on('error', common.mustNotCall());
client_stream.on('close', common.mustCall(() => {
client.close();
client.destroy();
Copy link
Member

Choose a reason for hiding this comment

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

It is still not clear to me why this callback

const writeCallback = (err) => {
waitingForWriteCallback = false;
writeCallbackErr = err;
done();
};
is not called. See #58252.

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.76%. Comparing base (3d30c30) to head (df7750e).
⚠️ Report is 4 commits behind head on main.

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     

see 39 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.

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. test Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants