Skip to content

Commit df7750e

Browse files
committed
test: fix flaky test-http2-close-while-writing
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
1 parent 3d30c30 commit df7750e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

test/parallel/test-http2-close-while-writing.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ const server = http2.createSecureServer({
2222
let client_stream;
2323

2424
server.on('session', common.mustCall(function(session) {
25+
session.on('error', common.mustNotCall());
2526
session.on('stream', common.mustCall(function(stream) {
2627
stream.resume();
2728
stream.on('data', function() {
2829
this.write(Buffer.alloc(1));
29-
process.nextTick(() => client_stream.destroy());
30+
process.nextTick(() => {
31+
if (!client_stream.destroyed) {
32+
client_stream.destroy();
33+
}
34+
});
3035
});
3136
}));
3237
}));
@@ -36,9 +41,11 @@ server.listen(0, common.mustCall(() => {
3641
ca,
3742
maxSessionMemory: 1000
3843
});
44+
client.on('error', common.mustNotCall());
3945
client_stream = client.request({ ':method': 'POST' });
46+
client_stream.on('error', common.mustNotCall());
4047
client_stream.on('close', common.mustCall(() => {
41-
client.close();
48+
client.destroy();
4249
server.close();
4350
}));
4451
client_stream.resume();

0 commit comments

Comments
 (0)