From 4a745f21671538925e382cc56c84b7a518449401 Mon Sep 17 00:00:00 2001 From: Renato Alcara Date: Sun, 1 Mar 2026 09:37:48 -0300 Subject: [PATCH] fix: move clearTimeout to finally block in fetchLatestBaileysVersion Ensures timer cleanup on both success and fetch rejection paths, preventing dangling timers when DNS/network fails before abort fires. Co-Authored-By: Claude Opus 4.6 --- src/Utils/generics.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Utils/generics.ts b/src/Utils/generics.ts index dec4653c..c4603f47 100644 --- a/src/Utils/generics.ts +++ b/src/Utils/generics.ts @@ -235,13 +235,17 @@ export const fetchLatestBaileysVersion = async (options: RequestInit & { timeout try { const controller = new AbortController() const timeout = setTimeout(() => controller.abort(), options.timeout ?? 5000) - const response = await fetch(URL, { - dispatcher: options.dispatcher, - method: 'GET', - headers: options.headers, - signal: controller.signal - }) - clearTimeout(timeout) + let response: Response + try { + response = await fetch(URL, { + dispatcher: options.dispatcher, + method: 'GET', + headers: options.headers, + signal: controller.signal + }) + } finally { + clearTimeout(timeout) + } if (!response.ok) { throw new Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, { statusCode: response.status }) }