-
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 PR-URL: #45922 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
1 parent
ca993f3
commit b58a604
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(); | ||
})); |