@@ -92,25 +92,24 @@ class RoundRobinPool extends PoolBase {
9292
9393 [ kGetDispatcher ] ( ) {
9494 const clientTtlOption = this [ kOptions ] . clientTtl
95- const clientsLength = this [ kClients ] . length
9695
9796 // If we have no clients yet, create one
98- if ( clientsLength === 0 ) {
97+ if ( this [ kClients ] . length === 0 ) {
9998 const dispatcher = this [ kFactory ] ( this [ kUrl ] , this [ kOptions ] )
10099 this [ kAddClient ] ( dispatcher )
101100 return dispatcher
102101 }
103102
104103 // Round-robin through existing clients
105104 let checked = 0
106- while ( checked < clientsLength ) {
107- this [ kIndex ] = ( this [ kIndex ] + 1 ) % clientsLength
105+ while ( checked < this [ kClients ] . length ) {
106+ this [ kIndex ] = ( this [ kIndex ] + 1 ) % this [ kClients ] . length
108107 const client = this [ kClients ] [ this [ kIndex ] ]
109108
110109 // Check if client is stale (TTL expired)
111110 if ( clientTtlOption != null && clientTtlOption > 0 && client . ttl && ( ( Date . now ( ) - client . ttl ) > clientTtlOption ) ) {
112111 this [ kRemoveClient ] ( client )
113- checked ++
112+ this [ kIndex ] --
114113 continue
115114 }
116115
@@ -123,7 +122,7 @@ class RoundRobinPool extends PoolBase {
123122 }
124123
125124 // All clients are busy, create a new one if we haven't reached the limit
126- if ( ! this [ kConnections ] || clientsLength < this [ kConnections ] ) {
125+ if ( ! this [ kConnections ] || this [ kClients ] . length < this [ kConnections ] ) {
127126 const dispatcher = this [ kFactory ] ( this [ kUrl ] , this [ kOptions ] )
128127 this [ kAddClient ] ( dispatcher )
129128 return dispatcher
0 commit comments