@@ -555,18 +555,18 @@ function workerInit() {
555555
556556  // obj is a net#Server or a dgram#Socket object. 
557557  cluster . _getServer  =  function ( obj ,  options ,  cb )  { 
558-     const  key  =  [  options . address , 
559-                 options . port , 
560-                 options . addressType , 
561-                 options . fd  ] . join ( ':' ) ; 
562-     if  ( indexes [ key ]  ===  undefined ) 
563-       indexes [ key ]  =  0 ; 
558+     const  indexesKey  =  [  options . address , 
559+                           options . port , 
560+                           options . addressType , 
561+                           options . fd  ] . join ( ':' ) ; 
562+     if  ( indexes [ indexesKey ]  ===  undefined ) 
563+       indexes [ indexesKey ]  =  0 ; 
564564    else 
565-       indexes [ key ] ++ ; 
565+       indexes [ indexesKey ] ++ ; 
566566
567567    const  message  =  util . _extend ( { 
568568      act : 'queryServer' , 
569-       index : indexes [ key ] , 
569+       index : indexes [ indexesKey ] , 
570570      data : null 
571571    } ,  options ) ; 
572572
@@ -576,9 +576,9 @@ function workerInit() {
576576      if  ( obj . _setServerData )  obj . _setServerData ( reply . data ) ; 
577577
578578      if  ( handle ) 
579-         shared ( reply ,  handle ,  cb ) ;   // Shared listen socket. 
579+         shared ( reply ,  handle ,  indexesKey ,   cb ) ;   // Shared listen socket. 
580580      else 
581-         rr ( reply ,  cb ) ;               // Round-robin. 
581+         rr ( reply ,  indexesKey ,   cb ) ;               // Round-robin. 
582582    } ) ; 
583583    obj . once ( 'listening' ,  function ( )  { 
584584      cluster . worker . state  =  'listening' ; 
@@ -590,14 +590,15 @@ function workerInit() {
590590  } ; 
591591
592592  // Shared listen socket. 
593-   function  shared ( message ,  handle ,  cb )  { 
593+   function  shared ( message ,  handle ,  indexesKey ,   cb )  { 
594594    var  key  =  message . key ; 
595595    // Monkey-patch the close() method so we can keep track of when it's 
596596    // closed. Avoids resource leaks when the handle is short-lived. 
597597    var  close  =  handle . close ; 
598598    handle . close  =  function ( )  { 
599599      send ( {  act : 'close' ,  key : key  } ) ; 
600600      delete  handles [ key ] ; 
601+       delete  indexes [ indexesKey ] ; 
601602      return  close . apply ( this ,  arguments ) ; 
602603    } ; 
603604    assert ( handles [ key ]  ===  undefined ) ; 
@@ -606,7 +607,7 @@ function workerInit() {
606607  } 
607608
608609  // Round-robin. Master distributes handles across workers. 
609-   function  rr ( message ,  cb )  { 
610+   function  rr ( message ,  indexesKey ,   cb )  { 
610611    if  ( message . errno ) 
611612      return  cb ( message . errno ,  null ) ; 
612613
@@ -627,6 +628,7 @@ function workerInit() {
627628      if  ( key  ===  undefined )  return ; 
628629      send ( {  act : 'close' ,  key : key  } ) ; 
629630      delete  handles [ key ] ; 
631+       delete  indexes [ indexesKey ] ; 
630632      key  =  undefined ; 
631633    } 
632634
0 commit comments