@@ -7,7 +7,7 @@ const { owner_symbol } = require('internal/async_hooks').symbols;
7
7
const Worker = require ( 'internal/cluster/worker' ) ;
8
8
const { internal, sendHelper } = require ( 'internal/cluster/utils' ) ;
9
9
const cluster = new EventEmitter ( ) ;
10
- const handles = { } ;
10
+ const handles = new Map ( ) ;
11
11
const indexes = new Map ( ) ;
12
12
const noop = ( ) => { } ;
13
13
@@ -111,12 +111,12 @@ function shared(message, handle, indexesKey, cb) {
111
111
112
112
handle . close = function ( ) {
113
113
send ( { act : 'close' , key } ) ;
114
- delete handles [ key ] ;
114
+ handles . delete ( key ) ;
115
115
indexes . delete ( indexesKey ) ;
116
116
return close . apply ( this , arguments ) ;
117
117
} . bind ( handle ) ;
118
- assert ( handles [ key ] === undefined ) ;
119
- handles [ key ] = handle ;
118
+ assert ( handles . has ( key ) === false ) ;
119
+ handles . set ( key , handle ) ;
120
120
cb ( message . errno , handle ) ;
121
121
}
122
122
@@ -144,7 +144,7 @@ function rr(message, indexesKey, cb) {
144
144
return ;
145
145
146
146
send ( { act : 'close' , key } ) ;
147
- delete handles [ key ] ;
147
+ handles . delete ( key ) ;
148
148
indexes . delete ( indexesKey ) ;
149
149
key = undefined ;
150
150
}
@@ -166,15 +166,15 @@ function rr(message, indexesKey, cb) {
166
166
handle . getsockname = getsockname ; // TCP handles only.
167
167
}
168
168
169
- assert ( handles [ key ] === undefined ) ;
170
- handles [ key ] = handle ;
169
+ assert ( handles . has ( key ) === false ) ;
170
+ handles . set ( key , handle ) ;
171
171
cb ( 0 , handle ) ;
172
172
}
173
173
174
174
// Round-robin connection.
175
175
function onconnection ( message , handle ) {
176
176
const key = message . key ;
177
- const server = handles [ key ] ;
177
+ const server = handles . get ( key ) ;
178
178
const accepted = server !== undefined ;
179
179
180
180
send ( { ack : message . seq , accepted } ) ;
@@ -207,17 +207,16 @@ function _disconnect(masterInitiated) {
207
207
}
208
208
}
209
209
210
- for ( var key in handles ) {
211
- const handle = handles [ key ] ;
212
- delete handles [ key ] ;
210
+ handles . forEach ( ( handle ) => {
213
211
waitingCount ++ ;
214
212
215
213
if ( handle [ owner_symbol ] )
216
214
handle [ owner_symbol ] . close ( checkWaitingCount ) ;
217
215
else
218
216
handle . close ( checkWaitingCount ) ;
219
- }
217
+ } ) ;
220
218
219
+ handles . clear ( ) ;
221
220
checkWaitingCount ( ) ;
222
221
}
223
222
0 commit comments