From 5cfdf21886917ab22e28aa326e22f1f0af23e185 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Sun, 22 Mar 2026 13:42:00 +0800 Subject: [PATCH] fix(typescript): clear timeout handle after fetch --- xdk-gen/templates/typescript/http_client.j2 | 26 ++++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/xdk-gen/templates/typescript/http_client.j2 b/xdk-gen/templates/typescript/http_client.j2 index 693adf84..f6e1db8a 100644 --- a/xdk-gen/templates/typescript/http_client.j2 +++ b/xdk-gen/templates/typescript/http_client.j2 @@ -116,20 +116,28 @@ export class HttpClient { // Handle timeout let signal = options.signal; + let timeoutId: ReturnType | undefined; + if (options.timeout && options.timeout > 0 && !signal) { const controller = new AbortController(); - setTimeout(() => controller.abort(), options.timeout); + timeoutId = setTimeout(() => controller.abort(), options.timeout); signal = controller.signal; } - const response = await this.fetch(url, { - method: options.method || 'GET', - headers: options.headers as any, - body: body as any, - signal: signal, - }); - - return response as HttpResponse; + try { + const response = await this.fetch(url, { + method: options.method || 'GET', + headers: options.headers as any, + body: body as any, + signal: signal, + }); + + return response as HttpResponse; + } finally { + if (timeoutId !== undefined) { + clearTimeout(timeoutId); + } + } } /**