File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { TokenCredential } from "@azure/identity";
77import { AzureAppConfigurationOptions , MaxRetries , MaxRetryDelayInMs } from "./AzureAppConfigurationOptions.js" ;
88import { isBrowser , isWebWorker } from "./requestTracing/utils.js" ;
99import * as RequestTracing from "./requestTracing/constants.js" ;
10+ import { shuffleList } from "./common/utils.js" ;
1011
1112const TCP_ORIGIN_KEY_NAME = "_origin._tcp" ;
1213const ALT_KEY_NAME = "_alt" ;
@@ -143,13 +144,7 @@ export class ConfigurationClientManager {
143144 throw new Error ( `Failed to build fallback clients, ${ error . message } ` ) ;
144145 }
145146
146- const srvTargetHosts = result as string [ ] ;
147- // Shuffle the list of SRV target hosts
148- for ( let i = srvTargetHosts . length - 1 ; i > 0 ; i -- ) {
149- const j = Math . floor ( Math . random ( ) * ( i + 1 ) ) ;
150- [ srvTargetHosts [ i ] , srvTargetHosts [ j ] ] = [ srvTargetHosts [ j ] , srvTargetHosts [ i ] ] ;
151- }
152-
147+ const srvTargetHosts = shuffleList ( result ) as string [ ] ;
153148 const newDynamicClients : ConfigurationClientWrapper [ ] = [ ] ;
154149 for ( const host of srvTargetHosts ) {
155150 if ( isValidEndpoint ( host , this . #validDomain) ) {
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT license.
3+
4+ export function shuffleList < T > ( array : T [ ] ) : T [ ] {
5+ for ( let i = array . length - 1 ; i > 0 ; i -- ) {
6+ const j = Math . floor ( Math . random ( ) * ( i + 1 ) ) ;
7+ [ array [ i ] , array [ j ] ] = [ array [ j ] , array [ i ] ] ;
8+ }
9+ return array ;
10+ }
You can’t perform that action at this time.
0 commit comments