forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
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: nodejs#30841 PR-URL: nodejs#45922 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
- Loading branch information
1 parent
8ec1b08
commit a03529d
Showing
4 changed files
with
43 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
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
26 changes: 26 additions & 0 deletions
26
test/parallel/test-net-write-cb-on-destroy-before-connect.js
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,26 @@ | ||
'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.on('connect', common.mustNotCall()); | ||
|
||
socket.connect({ | ||
port: server.address().port, | ||
}); | ||
|
||
assert(socket.connecting); | ||
|
||
socket.write('foo', common.expectsError({ | ||
code: 'ERR_SOCKET_CLOSED_BEFORE_CONNECTION', | ||
name: 'Error' | ||
})); | ||
|
||
socket.destroy(); | ||
server.close(); | ||
})); |