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";
7
7
import { AzureAppConfigurationOptions , MaxRetries , MaxRetryDelayInMs } from "./AzureAppConfigurationOptions.js" ;
8
8
import { isBrowser , isWebWorker } from "./requestTracing/utils.js" ;
9
9
import * as RequestTracing from "./requestTracing/constants.js" ;
10
+ import { shuffleList } from "./common/utils.js" ;
10
11
11
12
const TCP_ORIGIN_KEY_NAME = "_origin._tcp" ;
12
13
const ALT_KEY_NAME = "_alt" ;
@@ -143,13 +144,7 @@ export class ConfigurationClientManager {
143
144
throw new Error ( `Failed to build fallback clients, ${ error . message } ` ) ;
144
145
}
145
146
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 [ ] ;
153
148
const newDynamicClients : ConfigurationClientWrapper [ ] = [ ] ;
154
149
for ( const host of srvTargetHosts ) {
155
150
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