-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There are cases where the `'clientError'` event can be emitted multiple times, even if the socket is correctly destroyed. Fixes: #51073 PR-URL: #51204 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
- Loading branch information
1 parent
61d1535
commit f7b53d0
Showing
3 changed files
with
56 additions
and
18 deletions.
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,55 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// Test that the `'clientError'` event can be emitted multiple times even if the | ||
// socket is correctly destroyed and that no warning is raised. | ||
|
||
const assert = require('assert'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
process.on('warning', common.mustNotCall()); | ||
|
||
function socketListener(socket) { | ||
const firstByte = socket.read(1); | ||
if (firstByte === null) { | ||
socket.once('readable', () => { | ||
socketListener(socket); | ||
}); | ||
return; | ||
} | ||
|
||
socket.unshift(firstByte); | ||
httpServer.emit('connection', socket); | ||
} | ||
|
||
const netServer = net.createServer(socketListener); | ||
const httpServer = http.createServer(common.mustNotCall()); | ||
|
||
httpServer.once('clientError', common.mustCall((err, socket) => { | ||
assert.strictEqual(err.code, 'HPE_INVALID_METHOD'); | ||
assert.strictEqual(err.rawPacket.toString(), 'Q'); | ||
socket.destroy(); | ||
|
||
httpServer.once('clientError', common.mustCall((err) => { | ||
assert.strictEqual(err.code, 'HPE_INVALID_METHOD'); | ||
assert.strictEqual( | ||
err.rawPacket.toString(), | ||
'WE http://example.com HTTP/1.1\r\n\r\n' | ||
); | ||
})); | ||
})); | ||
|
||
netServer.listen(0, common.mustCall(() => { | ||
const socket = net.createConnection(netServer.address().port); | ||
|
||
socket.on('connect', common.mustCall(() => { | ||
socket.end('QWE http://example.com HTTP/1.1\r\n\r\n'); | ||
})); | ||
|
||
socket.on('close', () => { | ||
netServer.close(); | ||
}); | ||
|
||
socket.resume(); | ||
})); |
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