Skip to content

Commit b7f34df

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

File tree

2 files changed

+35
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)