File tree Expand file tree Collapse file tree 2 files changed +7
-21
lines changed Expand file tree Collapse file tree 2 files changed +7
-21
lines changed Original file line number Diff line number Diff line change @@ -531,14 +531,7 @@ Socket.prototype._final = function(cb) {
531531 // If still connecting - defer handling `_final` until 'connect' will happen
532532 if ( this . connecting ) {
533533 debug ( '_final: not yet connected' ) ;
534- if ( ! this . _finalizingOnConnect ) {
535- this . _finalizingOnConnect = true ;
536- this . once ( 'connect' , ( ) => {
537- this . _final ( cb ) ;
538- this . _finalizingOnConnect = false ;
539- } ) ;
540- }
541- return ;
534+ return this . once ( 'connect' , ( ) => this . _final ( cb ) ) ;
542535 }
543536
544537 if ( ! this . _handle )
@@ -810,8 +803,8 @@ Socket.prototype.destroySoon = function() {
810803 else if ( ! this . _destroyingOnFinish ) {
811804 this . _destroyingOnFinish = true ;
812805 this . once ( 'finish' , ( ) => {
813- this . destroy ( ) ;
814806 this . _destroyingOnFinish = false ;
807+ this . destroy ( ) ;
815808 } ) ;
816809 }
817810} ;
Original file line number Diff line number Diff line change @@ -3,20 +3,13 @@ require('../common');
33const { addresses } = require ( '../common/internet' ) ;
44
55const assert = require ( 'assert' ) ;
6- const net = require ( 'net' ) ;
6+ const { Socket } = require ( 'net' ) ;
77
8- const socket = new net . Socket ( ) ;
8+ const socket = new Socket ( ) ;
99socket . on ( 'error' , ( ) => {
1010 // noop
1111} ) ;
12- const connectOptions = { host : addresses . INVALID_HOST , port : 1234 } ;
13-
14- socket . connect ( connectOptions ) ;
15- socket . destroySoon ( ) ; // Adds "connect" and "finish" event listeners when socket has "writable" state
16- socket . destroy ( ) ; // Makes imideditly socket again "writable"
17-
18- socket . connect ( connectOptions ) ;
19- socket . destroySoon ( ) ; // Should not duplicate "connect" and "finish" event listeners
20-
12+ socket . connect ( { host : addresses . INVALID_HOST , port : 1234 } ) ;
13+ socket . destroySoon ( ) ;
14+ socket . destroySoon ( ) ;
2115assert . strictEqual ( socket . listeners ( 'finish' ) . length , 1 ) ;
22- assert . strictEqual ( socket . listeners ( 'connect' ) . length , 1 ) ;
You can’t perform that action at this time.
0 commit comments