1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const http = require('http'); 5const MakeDuplexPair = require('../common/duplexpair'); 6 7// Regression test for the crash reported in 8// https://github.com/nodejs/node/issues/15102 (httpParser.finish() is called 9// during httpParser.execute()): 10 11{ 12 const { clientSide, serverSide } = MakeDuplexPair(); 13 14 serverSide.on('data', common.mustCall((data) => { 15 assert.strictEqual(data.toString('utf8'), `\ 16GET / HTTP/1.1 17Expect: 100-continue 18Host: localhost:80 19Connection: close 20 21`.replace(/\n/g, '\r\n')); 22 23 setImmediate(() => { 24 serverSide.write('HTTP/1.1 100 Continue\r\n\r\n'); 25 }); 26 })); 27 28 const req = http.request({ 29 createConnection: common.mustCall(() => clientSide), 30 headers: { 31 'Expect': '100-continue' 32 } 33 }); 34 req.on('continue', common.mustCall((res) => { 35 let sync = true; 36 37 clientSide._writev = null; 38 clientSide._write = common.mustCall((chunk, enc, cb) => { 39 assert(sync); 40 // On affected versions of Node.js, the error would be emitted on `req` 41 // synchronously (i.e. before commit f663b31cc2aec), which would cause 42 // parser.finish() to be called while we are here in the 'continue' 43 // callback, which is inside a parser.execute() call. 44 45 assert.strictEqual(chunk.length, 4); 46 clientSide.destroy(new Error('sometimes the code just doesn’t work'), cb); 47 }); 48 req.on('error', common.mustCall()); 49 req.end('data'); 50 51 sync = false; 52 })); 53} 54