-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: handle socket.write(cb) edge case
Make sure that when calling `write()` on a connecting socket, the callback is called if the socket is destroyed before the connection is established. Fixes: #30841
- Loading branch information
1 parent
7738844
commit 3c5e0af
Showing
2 changed files
with
29 additions
and
0 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,24 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
const server = net.createServer(); | ||
server.listen(0, common.mustCall(() => { | ||
const socket = new net.Socket(); | ||
|
||
socket.connect({ | ||
port: server.address().port, | ||
}); | ||
|
||
assert(socket.connecting); | ||
|
||
socket.write('foo', common.expectsError({ | ||
code: 'ERR_SOCKET_CLOSED', | ||
name: 'Error' | ||
})); | ||
|
||
socket.destroy(); | ||
server.close(); | ||
})); |