From 8d4fcb7f65da9bd49ad823b125a2235fc1843748 Mon Sep 17 00:00:00 2001 From: Zhiyuan Liang Date: Thu, 19 Dec 2024 18:27:26 +0800 Subject: [PATCH] fix timeout --- src/ConfigurationClientManager.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ConfigurationClientManager.ts b/src/ConfigurationClientManager.ts index b11e9350..6510b7ff 100644 --- a/src/ConfigurationClientManager.ts +++ b/src/ConfigurationClientManager.ts @@ -140,13 +140,16 @@ export class ConfigurationClientManager { async #discoverFallbackClients(host: string) { let result; + let timeout; try { result = await Promise.race([ - new Promise((_, reject) => setTimeout(() => reject(new Error("SRV record query timed out.")), SRV_QUERY_TIMEOUT)), + new Promise((_, reject) => timeout = setTimeout(() => reject(new Error("SRV record query timed out.")), SRV_QUERY_TIMEOUT)), this.#querySrvTargetHost(host) ]); } catch (error) { throw new Error(`Failed to build fallback clients, ${error.message}`); + } finally { + clearTimeout(timeout); } const srvTargetHosts = shuffleList(result) as string[];