@@ -564,18 +564,18 @@ function workerInit() {
564564
565565  // obj is a net#Server or a dgram#Socket object. 
566566  cluster . _getServer  =  function ( obj ,  options ,  cb )  { 
567-     const  key  =  [  options . address , 
568-                 options . port , 
569-                 options . addressType , 
570-                 options . fd  ] . join ( ':' ) ; 
571-     if  ( indexes [ key ]  ===  undefined ) 
572-       indexes [ key ]  =  0 ; 
567+     const  indexesKey  =  [  options . address , 
568+                           options . port , 
569+                           options . addressType , 
570+                           options . fd  ] . join ( ':' ) ; 
571+     if  ( indexes [ indexesKey ]  ===  undefined ) 
572+       indexes [ indexesKey ]  =  0 ; 
573573    else 
574-       indexes [ key ] ++ ; 
574+       indexes [ indexesKey ] ++ ; 
575575
576576    const  message  =  util . _extend ( { 
577577      act : 'queryServer' , 
578-       index : indexes [ key ] , 
578+       index : indexes [ indexesKey ] , 
579579      data : null 
580580    } ,  options ) ; 
581581
@@ -585,9 +585,9 @@ function workerInit() {
585585      if  ( obj . _setServerData )  obj . _setServerData ( reply . data ) ; 
586586
587587      if  ( handle ) 
588-         shared ( reply ,  handle ,  cb ) ;   // Shared listen socket. 
588+         shared ( reply ,  handle ,  indexesKey ,   cb ) ;   // Shared listen socket. 
589589      else 
590-         rr ( reply ,  cb ) ;               // Round-robin. 
590+         rr ( reply ,  indexesKey ,   cb ) ;               // Round-robin. 
591591    } ) ; 
592592    obj . once ( 'listening' ,  function ( )  { 
593593      cluster . worker . state  =  'listening' ; 
@@ -599,14 +599,15 @@ function workerInit() {
599599  } ; 
600600
601601  // Shared listen socket. 
602-   function  shared ( message ,  handle ,  cb )  { 
602+   function  shared ( message ,  handle ,  indexesKey ,   cb )  { 
603603    var  key  =  message . key ; 
604604    // Monkey-patch the close() method so we can keep track of when it's 
605605    // closed. Avoids resource leaks when the handle is short-lived. 
606606    var  close  =  handle . close ; 
607607    handle . close  =  function ( )  { 
608608      send ( {  act : 'close' ,  key : key  } ) ; 
609609      delete  handles [ key ] ; 
610+       delete  indexes [ indexesKey ] ; 
610611      return  close . apply ( this ,  arguments ) ; 
611612    } ; 
612613    assert ( handles [ key ]  ===  undefined ) ; 
@@ -615,7 +616,7 @@ function workerInit() {
615616  } 
616617
617618  // Round-robin. Master distributes handles across workers. 
618-   function  rr ( message ,  cb )  { 
619+   function  rr ( message ,  indexesKey ,   cb )  { 
619620    if  ( message . errno ) 
620621      return  cb ( message . errno ,  null ) ; 
621622
@@ -636,6 +637,7 @@ function workerInit() {
636637      if  ( key  ===  undefined )  return ; 
637638      send ( {  act : 'close' ,  key : key  } ) ; 
638639      delete  handles [ key ] ; 
640+       delete  indexes [ indexesKey ] ; 
639641      key  =  undefined ; 
640642    } 
641643
0 commit comments