Skip to content

Commit 3b563d8

Browse files
committed
update
1 parent 1c80d41 commit 3b563d8

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/ConfigurationClientManager.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { TokenCredential } from "@azure/identity";
77
import { AzureAppConfigurationOptions, MaxRetries, MaxRetryDelayInMs } from "./AzureAppConfigurationOptions.js";
88
import { isBrowser, isWebWorker } from "./requestTracing/utils.js";
99
import * as RequestTracing from "./requestTracing/constants.js";
10+
import { shuffleList } from "./common/utils.js";
1011

1112
const TCP_ORIGIN_KEY_NAME = "_origin._tcp";
1213
const 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)) {

src/common/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

0 commit comments

Comments
 (0)