-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: use listenerCount when adding noop event
PR-URL: #46769 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
f94ef7c
commit 0d3faae
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Flags: --no-warnings | ||
|
||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
// This test sends an invalid character to a HTTP server and purposely | ||
// does not handle clientError (even if it sets an event handler). | ||
// | ||
// The idea is to let the server emit multiple errors on the socket, | ||
// mostly due to parsing error, and make sure they don't result | ||
// in leaking event listeners. | ||
|
||
{ | ||
let i = 0; | ||
let socket; | ||
process.on('warning', common.mustCall()); | ||
|
||
const server = http.createServer(common.mustNotCall()); | ||
|
||
server.on('clientError', common.mustCallAtLeast((err) => { | ||
assert.strictEqual(err.code, 'HPE_INVALID_METHOD'); | ||
assert.strictEqual(err.rawPacket.toString(), '*'); | ||
|
||
if (i === 20) { | ||
socket.end(); | ||
} else { | ||
socket.write('*'); | ||
i++; | ||
} | ||
}, 1)); | ||
|
||
server.listen(0, () => { | ||
socket = net.createConnection({ port: server.address().port }); | ||
|
||
socket.on('connect', () => { | ||
socket.write('*'); | ||
}); | ||
|
||
socket.on('close', () => { | ||
server.close(); | ||
}); | ||
}); | ||
} |