Skip to content

Commit 870c84c

Browse files
committed
test: cover a raw socket close in http2 session timeout
The existing test only covers a graceful close, where the client sends GOAWAY. Destroy the client's TCP socket instead, so the server closes the session through socketOnClose() -> closeSession() directly and no 'goaway' event fires. Signed-off-by: huang <13165998033@163.com>
1 parent 24461fe commit 870c84c

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
const assert = require('assert');
7+
const http2 = require('http2');
8+
const net = require('net');
9+
10+
// Same as test-http2-session-timeout-cleared-on-close.js, but the client's
11+
// TCP socket is destroyed without sending GOAWAY.
12+
const server = http2.createServer();
13+
server.setTimeout(30_000, common.mustNotCall());
14+
15+
server.on('session', common.mustCall((session) => {
16+
session.on('goaway', common.mustNotCall());
17+
session.on('close', common.mustCall(() => {
18+
assert.strictEqual(session.timeout, 0);
19+
server.close();
20+
}));
21+
}));
22+
23+
server.on('stream', common.mustCall((stream) => {
24+
stream.respond({ ':status': 200 });
25+
stream.end('ok');
26+
}));
27+
28+
server.listen(0, common.mustCall(() => {
29+
let socket;
30+
const client = http2.connect(`http://localhost:${server.address().port}`, {
31+
createConnection: (url) => (socket = net.connect(url.port, url.hostname)),
32+
});
33+
client.on('error', () => {});
34+
const req = client.request();
35+
req.on('error', () => {});
36+
req.resume();
37+
req.on('end', common.mustCall(() => socket.destroy()));
38+
}));

0 commit comments

Comments
 (0)