Skip to content

Commit 56ba9ab

Browse files
committed
http: remove all internal listeners
1 parent 4ecc6a4 commit 56ba9ab

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/_http_server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,10 @@ const requestHeaderFieldsTooLargeResponse = Buffer.from(
762762
function socketOnError(e) {
763763
// Ignore further errors
764764
this.removeListener('error', socketOnError);
765-
this.on('error', noop);
765+
766+
if (!this.listenerCount('error')) {
767+
this.on('error', noop);
768+
}
766769

767770
if (!this.server.emit('clientError', e, this)) {
768771
if (this.writable && this.bytesWritten === 0) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const http = require('http');
5+
const net = require('net');
6+
7+
const server = http.createServer((req, res) => {
8+
res.writeHead(200);
9+
res.end('response');
10+
});
11+
12+
server.on('clientError', common.mustCallAtLeast(() => {}, 1));
13+
process.on('warning', common.mustNotCall());
14+
15+
server.listen(0, () => {
16+
const client = net.createConnection({ port: server.address().port });
17+
18+
client.on('connect', () => {
19+
for (let i = 0; i < 20; i++) {
20+
setTimeout(() => {
21+
client.write('*\r\n');
22+
}, common.platformTimeout(i * 10));
23+
}
24+
25+
setTimeout(() => {
26+
client.end();
27+
server.close();
28+
}, common.platformTimeout(1000));
29+
});
30+
});

0 commit comments

Comments
 (0)