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