File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -533,7 +533,10 @@ Socket.prototype._final = function(cb) {
533533 debug ( '_final: not yet connected' ) ;
534534 if ( ! this . _finalizingOnConnect ) {
535535 this . _finalizingOnConnect = true ;
536- this . once ( 'connect' , ( ) => this . _final ( cb ) ) ;
536+ this . once ( 'connect' , ( ) => {
537+ this . _final ( cb ) ;
538+ this . _finalizingOnConnect = false ;
539+ } ) ;
537540 }
538541 return ;
539542 }
@@ -806,7 +809,10 @@ Socket.prototype.destroySoon = function() {
806809 this . destroy ( ) ;
807810 else if ( ! this . _destroyingOnFinish ) {
808811 this . _destroyingOnFinish = true ;
809- this . once ( 'finish' , this . destroy ) ;
812+ this . once ( 'finish' , ( ) => {
813+ this . destroy ( ) ;
814+ this . _destroyingOnFinish = false ;
815+ } ) ;
810816 }
811817} ;
812818
Original file line number Diff line number Diff line change @@ -9,10 +9,14 @@ const socket = new net.Socket();
99socket . on ( 'error' , ( ) => {
1010 // noop
1111} ) ;
12- socket . connect ( { host : addresses . INVALID_HOST , port : 1234 } ) ;
13- socket . destroySoon ( ) ;
14- socket . destroySoon ( ) ;
15- const finishListenersCount = socket . listeners ( 'finish' ) . length ;
16- const connectListenersCount = socket . listeners ( 'connect' ) . length ;
17- assert . strictEqual ( finishListenersCount , 1 ) ;
18- assert . strictEqual ( connectListenersCount , 1 ) ;
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+
21+ assert . 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