Skip to content

Commit 1aa5e97

Browse files
committed
Fixups
1 parent 7b7db3b commit 1aa5e97

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

doc/api/errors.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,6 +2573,13 @@ could not be determined.
25732573

25742574
An attempt was made to operate on an already closed socket.
25752575

2576+
<a id="ERR_SOCKET_CLOSED_BEFORE_CONNECTION"></a>
2577+
2578+
### `ERR_SOCKET_CLOSED_BEFORE_CONNECTION`
2579+
2580+
When calling [`net.Socket.write()`][] on a connecting socket and the socket was
2581+
closed before the connection was established.
2582+
25762583
<a id="ERR_SOCKET_DGRAM_IS_CONNECTED"></a>
25772584

25782585
### `ERR_SOCKET_DGRAM_IS_CONNECTED`
@@ -3586,6 +3593,7 @@ The native call from `process.cpuUsage` could not be processed.
35863593
[`http`]: http.md
35873594
[`https`]: https.md
35883595
[`libuv Error handling`]: https://docs.libuv.org/en/v1.x/errors.html
3596+
[`net.Socket.write()`]: net.md#socketwritedata-encoding-callback
35893597
[`net`]: net.md
35903598
[`new URL(input)`]: url.md#new-urlinput-base
35913599
[`new URLSearchParams(iterable)`]: url.md#new-urlsearchparamsiterable

lib/internal/errors.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,9 @@ E('ERR_SOCKET_BUFFER_SIZE',
15661566
'Could not get or set buffer size',
15671567
SystemError);
15681568
E('ERR_SOCKET_CLOSED', 'Socket is closed', Error);
1569+
E('ERR_SOCKET_CLOSED_BEFORE_CONNECTION',
1570+
'Socket was closed before connection established',
1571+
Error);
15691572
E('ERR_SOCKET_DGRAM_IS_CONNECTED', 'Already connected', Error);
15701573
E('ERR_SOCKET_DGRAM_NOT_CONNECTED', 'Not connected', Error);
15711574
E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running', Error);

lib/net.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const {
9898
ERR_SERVER_ALREADY_LISTEN,
9999
ERR_SERVER_NOT_RUNNING,
100100
ERR_SOCKET_CLOSED,
101+
ERR_SOCKET_CLOSED_BEFORE_CONNECTION,
101102
ERR_MISSING_ARGS,
102103
},
103104
aggregateErrors,
@@ -900,7 +901,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
900901
this._writeGeneric(writev, data, encoding, cb);
901902
});
902903
function onClose() {
903-
cb(new ERR_SOCKET_CLOSED());
904+
cb(new ERR_SOCKET_CLOSED_BEFORE_CONNECTION());
904905
}
905906
this.once('close', onClose);
906907
return;

test/parallel/test-net-write-cb-on-destroy.js renamed to test/parallel/test-net-write-cb-on-destroy-before-connect.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ const server = net.createServer();
88
server.listen(0, common.mustCall(() => {
99
const socket = new net.Socket();
1010

11+
socket.on('connect', common.mustNotCall());
12+
1113
socket.connect({
1214
port: server.address().port,
1315
});
1416

1517
assert(socket.connecting);
1618

1719
socket.write('foo', common.expectsError({
18-
code: 'ERR_SOCKET_CLOSED',
20+
code: 'ERR_SOCKET_CLOSED_BEFORE_CONNECTION',
1921
name: 'Error'
2022
}));
2123

0 commit comments

Comments
 (0)