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: https://github.com/nodejs/node/issues/30841
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Santiago Gimeno authored and GitHub committed 2023-01-01 23:07:34 +00:00
1 parent 8ec1b0870b
commit a03529d828
4 files changed
+43

No files matched your search

+8
View File
@@ -2573,6 +2573,13 @@ could not be determined.
An attempt was made to operate on an already closed socket.
<a id="ERR_SOCKET_CLOSED_BEFORE_CONNECTION"></a>
### `ERR_SOCKET_CLOSED_BEFORE_CONNECTION`
When calling [`net.Socket.write()`][] on a connecting socket and the socket was
closed before the connection was established.
<a id="ERR_SOCKET_DGRAM_IS_CONNECTED"></a>
### `ERR_SOCKET_DGRAM_IS_CONNECTED`
@@ -3586,6 +3593,7 @@ The native call from `process.cpuUsage` could not be processed.
[`http`]: http.md
[`https`]: https.md
[`libuv Error handling`]: https://docs.libuv.org/en/v1.x/errors.html
[`net.Socket.write()`]: net.md#socketwritedata-encoding-callback
[`net`]: net.md
[`new URL(input)`]: url.md#new-urlinput-base
[`new URLSearchParams(iterable)`]: url.md#new-urlsearchparamsiterable