-
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.
net: wait for shutdown to complete before closing
When not allowing half open, handle.close would be invoked before shutdown has been called and completed causing a potential data race. Fixes: #32486 (comment) PR-URL: #32491 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
Showing
4 changed files
with
39 additions
and
6 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
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,25 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
const server = net.createServer(common.mustCall((socket) => { | ||
socket.end(Buffer.alloc(1024)); | ||
})).listen(0, common.mustCall(() => { | ||
const socket = net.connect(server.address().port); | ||
assert.strictEqual(socket.allowHalfOpen, false); | ||
socket.resume(); | ||
socket.on('end', common.mustCall(() => { | ||
process.nextTick(() => { | ||
// Ensure socket is not destroyed straight away | ||
// without proper shutdown. | ||
assert(!socket.destroyed); | ||
server.close(); | ||
}); | ||
})); | ||
socket.on('finish', common.mustCall(() => { | ||
assert(!socket.destroyed); | ||
})); | ||
socket.on('close', common.mustCall()); | ||
})); |