File tree Expand file tree Collapse file tree 2 files changed +31
-12
lines changed
Expand file tree Collapse file tree 2 files changed +31
-12
lines changed Original file line number Diff line number Diff line change @@ -654,26 +654,24 @@ function workerInit() {
654654
655655 Worker . prototype . disconnect = function ( ) {
656656 this . suicide = true ;
657- var waitingHandles = 0 ;
657+ let waitingCount = 1 ;
658658
659- function checkRemainingHandles ( ) {
660- waitingHandles -- ;
661- if ( waitingHandles === 0 ) {
659+ function checkWaitingCount ( ) {
660+ waitingCount -- ;
661+ if ( waitingCount === 0 ) {
662+ send ( { act : 'suicide' } ) ;
662663 process . disconnect ( ) ;
663664 }
664665 }
665666
666- for ( var key in handles ) {
667- var handle = handles [ key ] ;
667+ for ( const key in handles ) {
668+ const handle = handles [ key ] ;
668669 delete handles [ key ] ;
669- waitingHandles ++ ;
670- handle . owner . close ( checkRemainingHandles ) ;
671- }
672-
673- if ( waitingHandles === 0 ) {
674- process . disconnect ( ) ;
670+ waitingCount ++ ;
671+ handle . owner . close ( checkWaitingCount ) ;
675672 }
676673
674+ checkWaitingCount ( ) ;
677675 } ;
678676
679677 Worker . prototype . destroy = function ( ) {
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+ const cluster = require ( 'cluster' ) ;
5+
6+ if ( cluster . isMaster ) {
7+ const worker = cluster . fork ( ) ;
8+ let disconnected = false ;
9+
10+ worker . on ( 'disconnect' , common . mustCall ( function ( ) {
11+ assert . strictEqual ( worker . suicide , true ) ;
12+ disconnected = true ;
13+ } ) ) ;
14+
15+ worker . on ( 'exit' , common . mustCall ( function ( ) {
16+ assert . strictEqual ( worker . suicide , true ) ;
17+ assert . strictEqual ( disconnected , true ) ;
18+ } ) ) ;
19+ } else {
20+ cluster . worker . disconnect ( ) ;
21+ }
You can’t perform that action at this time.
0 commit comments