Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 18c057a

Browse filesBrowse files
Brett Kiefertargos
authored andcommitted
net: emit 'close' when socket ends before connect
Don't set `writable` to true when a socket connects if the socket is already in an ending state. In the existing code, afterConnect always set `writable` to true. This has been the case for a long time, but previous to commit 9b7a691, the socket would still be destroyed by `destroySoon` and emit a `'close'` event. Since that commit removed this masking behavior, we have relied on maybeDestroy to destroy the socket when the readble state is ended, and that won't happen if `writable` is set to true. If the socket has `allowHalfOpen` set to true, then `destroy` will still not be called and `'close'` will not be emitted. PR-URL: #21290 Fixes: #21268 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 6285fe9 commit 18c057a
Copy full SHA for 18c057a

File tree

Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,8 @@ function afterConnect(status, handle, req, readable, writable) {
11381138

11391139
if (status === 0) {
11401140
self.readable = readable;
1141-
self.writable = writable;
1141+
if (!self._writableState.ended)
1142+
self.writable = writable;
11421143
self._unrefTimer();
11431144

11441145
self.emit('connect');
Collapse file
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const net = require('net');
6+
7+
const server = net.createServer();
8+
9+
server.listen(common.mustCall(() => {
10+
const socket = net.createConnection(server.address().port);
11+
socket.on('close', common.mustCall(() => server.close()));
12+
socket.end();
13+
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.