@@ -7,7 +7,7 @@ const { owner_symbol } = require('internal/async_hooks').symbols;
77const Worker = require ( 'internal/cluster/worker' ) ;
88const { internal, sendHelper } = require ( 'internal/cluster/utils' ) ;
99const cluster = new EventEmitter ( ) ;
10- const handles = { } ;
10+ const handles = new Map ( ) ;
1111const indexes = new Map ( ) ;
1212const noop = ( ) => { } ;
1313
@@ -111,12 +111,12 @@ function shared(message, handle, indexesKey, cb) {
111111
112112 handle . close = function ( ) {
113113 send ( { act : 'close' , key } ) ;
114- delete handles [ key ] ;
114+ handles . delete ( key ) ;
115115 indexes . delete ( indexesKey ) ;
116116 return close . apply ( this , arguments ) ;
117117 } . bind ( handle ) ;
118- assert ( handles [ key ] === undefined ) ;
119- handles [ key ] = handle ;
118+ assert ( handles . has ( key ) === false ) ;
119+ handles . set ( key , handle ) ;
120120 cb ( message . errno , handle ) ;
121121}
122122
@@ -144,7 +144,7 @@ function rr(message, indexesKey, cb) {
144144 return ;
145145
146146 send ( { act : 'close' , key } ) ;
147- delete handles [ key ] ;
147+ handles . delete ( key ) ;
148148 indexes . delete ( indexesKey ) ;
149149 key = undefined ;
150150 }
@@ -166,15 +166,15 @@ function rr(message, indexesKey, cb) {
166166 handle . getsockname = getsockname ; // TCP handles only.
167167 }
168168
169- assert ( handles [ key ] === undefined ) ;
170- handles [ key ] = handle ;
169+ assert ( handles . has ( key ) === false ) ;
170+ handles . set ( key , handle ) ;
171171 cb ( 0 , handle ) ;
172172}
173173
174174// Round-robin connection.
175175function onconnection ( message , handle ) {
176176 const key = message . key ;
177- const server = handles [ key ] ;
177+ const server = handles . get ( key ) ;
178178 const accepted = server !== undefined ;
179179
180180 send ( { ack : message . seq , accepted } ) ;
@@ -207,17 +207,16 @@ function _disconnect(masterInitiated) {
207207 }
208208 }
209209
210- for ( var key in handles ) {
211- const handle = handles [ key ] ;
212- delete handles [ key ] ;
210+ handles . forEach ( ( handle ) => {
213211 waitingCount ++ ;
214212
215213 if ( handle [ owner_symbol ] )
216214 handle [ owner_symbol ] . close ( checkWaitingCount ) ;
217215 else
218216 handle . close ( checkWaitingCount ) ;
219- }
217+ } ) ;
220218
219+ handles . clear ( ) ;
221220 checkWaitingCount ( ) ;
222221}
223222
0 commit comments