1'use strict'; 2 3const common = require('../common'); 4const http = require('http'); 5const net = require('net'); 6const { finished } = require('stream'); 7 8const headers = 9 'GET / HTTP/1.1\r\n' + 10 'Host: localhost\r\n' + 11 'Connection: keep-alive\r\n' + 12 'Agent: node\r\n'; 13 14let sendCharEvery = 1000; 15 16const server = http.createServer(common.mustCall((req, res) => { 17 res.writeHead(200); 18 res.end(); 19})); 20 21// Pass a REAL env variable to shortening up the default 22// value which is 40s otherwise this is useful for manual 23// testing 24if (!process.env.REAL) { 25 sendCharEvery = common.platformTimeout(10); 26 server.headersTimeout = 2 * sendCharEvery; 27} 28 29server.once('timeout', common.mustCall((socket) => { 30 socket.destroy(); 31})); 32 33server.listen(0, () => { 34 const client = net.connect(server.address().port); 35 client.write(headers); 36 // Finish the first request 37 client.write('\r\n'); 38 // second request 39 client.write(headers); 40 client.write('X-CRASH: '); 41 42 const interval = setInterval(() => { 43 client.write('a'); 44 }, sendCharEvery); 45 46 client.resume(); 47 finished(client, common.mustCall((err) => { 48 clearInterval(interval); 49 server.close(); 50 })); 51}); 52