forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-h2leak-destroy-session-on-socket-ended.js
80 lines (64 loc) · 1.69 KB
/
test-h2leak-destroy-session-on-socket-ended.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
// Flags: --expose-gc
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const tls = require('tls');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const registry = new FinalizationRegistry(common.mustCall((name) => {
assert(name, 'session');
}));
const server = http2.createSecureServer({
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem'),
});
let firstServerStream;
server.on('secureConnection', (s) => {
console.log('secureConnection');
s.on('end', () => {
console.log(s.destroyed); // false !!
s.destroy();
firstServerStream.session.destroy();
firstServerStream = null;
setImmediate(() => {
global.gc();
global.gc();
server.close();
});
});
});
server.on('session', (s) => {
registry.register(s, 'session');
});
server.on('stream', (stream) => {
console.log('stream...');
stream.write('a'.repeat(1024));
firstServerStream = stream;
setImmediate(() => console.log('Draining setImmediate after writing'));
});
server.listen(() => {
client();
});
const h2fstStream = [
'UFJJICogSFRUUC8yLjANCg0KU00NCg0K',
// http message (1st stream:)
'AAAABAAAAAAA',
'AAAPAQUAAAABhIJBiqDkHROdCbjwHgeG',
];
function client() {
const client = tls.connect({
port: server.address().port,
host: 'localhost',
rejectUnauthorized: false,
ALPNProtocols: ['h2']
}, () => {
client.end(Buffer.concat(h2fstStream.map((s) => Buffer.from(s, 'base64'))), (err) => {
assert.ifError(err);
});
});
client.on('error', (error) => {
console.error('Connection error:', error);
});
}