1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const assert = require('assert'); 8const fs = require('fs'); 9const http2 = require('http2'); 10 11const { 12 NGHTTP2_INTERNAL_ERROR 13} = http2.constants; 14 15const errorCheck = common.expectsError({ 16 code: 'ERR_HTTP2_STREAM_ERROR', 17 name: 'Error', 18 message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR' 19}, 2); 20 21const server = http2.createServer(); 22server.on('stream', (stream) => { 23 let fd = 2; 24 25 // Get first known bad file descriptor. 26 try { 27 while (fs.fstatSync(++fd)); 28 } catch { 29 // Do nothing; we now have an invalid fd 30 } 31 32 stream.respondWithFD(fd); 33 stream.on('error', errorCheck); 34}); 35server.listen(0, () => { 36 37 const client = http2.connect(`http://localhost:${server.address().port}`); 38 const req = client.request(); 39 40 req.on('response', common.mustCall()); 41 req.on('error', errorCheck); 42 req.on('data', common.mustNotCall()); 43 req.on('end', common.mustCall(() => { 44 assert.strictEqual(req.rstCode, NGHTTP2_INTERNAL_ERROR); 45 client.close(); 46 server.close(); 47 })); 48 req.end(); 49}); 50