File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,6 +90,10 @@ class RoundRobinPicker implements Picker {
9090 }
9191}
9292
93+ function rotateArray < T > ( list : T [ ] , startIndex : number ) {
94+ return [ ...list . slice ( startIndex ) , ...list . slice ( 0 , startIndex ) ] ;
95+ }
96+
9397export class RoundRobinLoadBalancer implements LoadBalancer {
9498 private children : LeafLoadBalancer [ ] = [ ] ;
9599
@@ -228,7 +232,8 @@ export class RoundRobinLoadBalancer implements LoadBalancer {
228232 }
229233 return true ;
230234 }
231- const endpointList = maybeEndpointList . value ;
235+ const startIndex = ( Math . random ( ) * maybeEndpointList . value . length ) | 0 ;
236+ const endpointList = rotateArray ( maybeEndpointList . value , startIndex ) ;
232237 this . resetSubchannelList ( ) ;
233238 if ( endpointList . length === 0 ) {
234239 const errorMessage = `No addresses resolved. Resolution note: ${ resolutionNote } ` ;
You can’t perform that action at this time.
0 commit comments