Skip to content

Commit 636e4e0

Browse files
addaleaxBridgeAR
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 <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 56cd911 commit 636e4e0

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

lib/net.js

+8-23
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,6 @@ Socket.prototype._unrefTimer = function _unrefTimer() {
336336
};
337337

338338

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

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

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

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

374359
if (err)
375360
return this.destroy(errnoException(err, 'shutdown'));
@@ -388,7 +373,7 @@ function afterShutdown(status, handle) {
388373
if (self.destroyed)
389374
return;
390375

391-
if (self._readableState.ended) {
376+
if (!self.readable || self._readableState.ended) {
392377
debug('readableState ended, destroying');
393378
self.destroy();
394379
}

0 commit comments

Comments
 (0)