1'use strict'; 2 3const common = require('../common'); 4const { mustCall } = common; 5 6if (!common.hasCrypto) 7 common.skip('missing crypto'); 8 9const http2 = require('http2'); 10const assert = require('assert'); 11 12const { 13 HTTP2_HEADER_PATH, 14 HTTP2_HEADER_METHOD, 15} = http2.constants; 16 17// This tests verifies that calling `req.socket.destroy()` via 18// setImmediate does not crash. 19// Fixes https://github.com/nodejs/node/issues/22855. 20 21const app = http2.createServer(mustCall((req, res) => { 22 res.end('hello'); 23 setImmediate(() => req.socket.destroy()); 24})); 25 26app.listen(0, mustCall(() => { 27 const session = http2.connect(`http://localhost:${app.address().port}`); 28 const request = session.request({ 29 [HTTP2_HEADER_PATH]: '/', 30 [HTTP2_HEADER_METHOD]: 'get' 31 }); 32 request.once('response', mustCall((headers, flags) => { 33 let data = ''; 34 request.on('data', (chunk) => { data += chunk; }); 35 request.on('end', mustCall(() => { 36 assert.strictEqual(data, 'hello'); 37 session.close(); 38 app.close(); 39 })); 40 })); 41 request.end(); 42})); 43