Skip to content

Commit

Permalink
http: remove all internal listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda committed Jun 27, 2022
1 parent 4ecc6a4 commit 56ba9ab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,10 @@ const requestHeaderFieldsTooLargeResponse = Buffer.from(
function socketOnError(e) {
// Ignore further errors
this.removeListener('error', socketOnError);
this.on('error', noop);

if (!this.listenerCount('error')) {
this.on('error', noop);
}

if (!this.server.emit('clientError', e, this)) {
if (this.writable && this.bytesWritten === 0) {
Expand Down
30 changes: 30 additions & 0 deletions test/parallel/test-http-socket-listeners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const common = require('../common');
const http = require('http');
const net = require('net');

const server = http.createServer((req, res) => {
res.writeHead(200);
res.end('response');
});

server.on('clientError', common.mustCallAtLeast(() => {}, 1));
process.on('warning', common.mustNotCall());

server.listen(0, () => {
const client = net.createConnection({ port: server.address().port });

client.on('connect', () => {
for (let i = 0; i < 20; i++) {
setTimeout(() => {
client.write('*\r\n');
}, common.platformTimeout(i * 10));
}

setTimeout(() => {
client.end();
server.close();
}, common.platformTimeout(1000));
});
});

0 comments on commit 56ba9ab

Please sign in to comment.