Skip to content

Commit 10a2727

Browse 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

1 file changed

Lines changed: 8 additions & 23 deletions

File tree

‎lib/net.js‎

Lines 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-
functionshutdownSocket(self,callback){
339-
varreq=newShutdownWrap();
340-
req.oncomplete=afterShutdown;
341-
req.handle=self._handle;
342-
req.callback=callback;
343-
returnself._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
returnthis.once('connect',()=>this._final(cb));
353345
}
354346

355-
if(!this.readable||this._readableState.ended){
356-
debug('_final: ended, destroy',this._readableState);
357-
cb();
358-
returnthis.destroy();
359-
}
347+
if(!this._handle)
348+
returncb();
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-
returnthis.destroy();
367-
}
368-
369-
varerr=defaultTriggerAsyncIdScope(
370-
this[async_id_symbol],shutdownSocket,this,cb
371-
);
352+
varreq=newShutdownWrap();
353+
req.oncomplete=afterShutdown;
354+
req.handle=this._handle;
355+
req.callback=cb;
356+
varerr=this._handle.shutdown(req);
372357

373358
if(err)
374359
returnthis.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)