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 10a2727

Browse filesBrowse files
addaleaxMylesBorins
authored andcommitted
net: simplify Socket.prototype._final
Remove conditions that should be irrelevant since we started using `_final`, as well as an extra `defaultTriggerAsyncIdScope()` call which is unnecessary because there is an equivalent scope already present on the native side. PR-URL: #24075 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d8ac55a commit 10a2727
Copy full SHA for 10a2727

File tree

Expand file treeCollapse file tree

1 file changed

+8
-23
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-23
lines changed
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+8-23Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,6 @@ Socket.prototype._unrefTimer = function _unrefTimer() {
335335
};
336336

337337

338-
function shutdownSocket(self, callback) {
339-
var req = new ShutdownWrap();
340-
req.oncomplete = afterShutdown;
341-
req.handle = self._handle;
342-
req.callback = callback;
343-
return self._handle.shutdown(req);
344-
}
345-
346338
// the user has called .end(), and all the bytes have been
347339
// sent out to the other side.
348340
Socket.prototype._final = function(cb) {
@@ -352,23 +344,16 @@ Socket.prototype._final = function(cb) {
352344
return this.once('connect', () => this._final(cb));
353345
}
354346

355-
if (!this.readable || this._readableState.ended) {
356-
debug('_final: ended, destroy', this._readableState);
357-
cb();
358-
return this.destroy();
359-
}
347+
if (!this._handle)
348+
return cb();
360349

361350
debug('_final: not ended, call shutdown()');
362351

363-
// otherwise, just shutdown, or destroy() if not possible
364-
if (!this._handle || !this._handle.shutdown) {
365-
cb();
366-
return this.destroy();
367-
}
368-
369-
var err = defaultTriggerAsyncIdScope(
370-
this[async_id_symbol], shutdownSocket, this, cb
371-
);
352+
var req = new ShutdownWrap();
353+
req.oncomplete = afterShutdown;
354+
req.handle = this._handle;
355+
req.callback = cb;
356+
var err = this._handle.shutdown(req);
372357

373358
if (err)
374359
return this.destroy(errnoException(err, 'shutdown'));
@@ -387,7 +372,7 @@ function afterShutdown(status, handle) {
387372
if (self.destroyed)
388373
return;
389374

390-
if (self._readableState.ended) {
375+
if (!self.readable || self._readableState.ended) {
391376
debug('readableState ended, destroying');
392377
self.destroy();
393378
}

0 commit comments

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