@@ -27,6 +27,7 @@ const {
27
27
ArrayPrototypePop,
28
28
ArrayPrototypePush,
29
29
ArrayPrototypeShift,
30
+ ArrayPrototypeSome,
30
31
ArrayPrototypeSplice,
31
32
FunctionPrototypeCall,
32
33
NumberIsNaN,
@@ -390,10 +391,10 @@ function installListeners(agent, s, options) {
390
391
// Destroy if in free list.
391
392
// TODO(ronag): Always destroy, even if not in free list.
392
393
const sockets = agent . freeSockets ;
393
- for ( const name of ObjectKeys ( sockets ) ) {
394
- if ( ArrayPrototypeIncludes ( sockets [ name ] , s ) ) {
395
- return s . destroy ( ) ;
396
- }
394
+ if ( ArrayPrototypeSome ( ObjectKeys ( sockets ) , ( name ) =>
395
+ ArrayPrototypeIncludes ( sockets [ name ] , s )
396
+ ) ) {
397
+ return s . destroy ( ) ;
397
398
}
398
399
}
399
400
s . on ( 'timeout' , onTimeout ) ;
@@ -449,7 +450,9 @@ Agent.prototype.removeSocket = function removeSocket(s, options) {
449
450
// There might be older requests in a different origin, but
450
451
// if the origin which releases the socket has pending requests
451
452
// that will be prioritized.
452
- for ( const prop of ObjectKeys ( this . requests ) ) {
453
+ const keys = ObjectKeys ( this . requests ) ;
454
+ for ( let i = 0 ; i < keys . length ; i ++ ) {
455
+ const prop = keys [ i ] ;
453
456
// Check whether this specific origin is already at maxSockets
454
457
if ( this . sockets [ prop ] && this . sockets [ prop ] . length ) break ;
455
458
debug ( 'removeSocket, have a request with different origin,' +
0 commit comments