Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
linglingye001 committed Nov 18, 2024
1 parent 1c80d41 commit 3b563d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/ConfigurationClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TokenCredential } from "@azure/identity";
import { AzureAppConfigurationOptions, MaxRetries, MaxRetryDelayInMs } from "./AzureAppConfigurationOptions.js";
import { isBrowser, isWebWorker } from "./requestTracing/utils.js";
import * as RequestTracing from "./requestTracing/constants.js";
import { shuffleList } from "./common/utils.js";

const TCP_ORIGIN_KEY_NAME = "_origin._tcp";
const ALT_KEY_NAME = "_alt";
Expand Down Expand Up @@ -143,13 +144,7 @@ export class ConfigurationClientManager {
throw new Error(`Failed to build fallback clients, ${error.message}`);
}

const srvTargetHosts = result as string[];
// Shuffle the list of SRV target hosts
for (let i = srvTargetHosts.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[srvTargetHosts[i], srvTargetHosts[j]] = [srvTargetHosts[j], srvTargetHosts[i]];
}

const srvTargetHosts = shuffleList(result) as string[];
const newDynamicClients: ConfigurationClientWrapper[] = [];
for (const host of srvTargetHosts) {
if (isValidEndpoint(host, this.#validDomain)) {
Expand Down
10 changes: 10 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export function shuffleList<T>(array: T[]): T[] {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}

0 comments on commit 3b563d8

Please sign in to comment.