From 79ee40037bacfa7b2d6e1a2e844a609dda1f7bed Mon Sep 17 00:00:00 2001 From: Renato Alcara Date: Sun, 1 Mar 2026 09:41:43 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20add=20timeout=20to=20fetchLatestBaileysV?= =?UTF-8?q?ersion=20to=20prevent=20hanging=20conn=E2=80=A6=20(#243)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: add timeout to fetchLatestBaileysVersion to prevent hanging connections AbortController with 5s default timeout prevents indefinite blocking when GitHub is unreachable (DNS failure, network issues). Falls back to bundled version via existing catch block. Ref: Baileys#2385. * 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. --- src/Utils/generics.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Utils/generics.ts b/src/Utils/generics.ts index d328a58d..c4603f47 100644 --- a/src/Utils/generics.ts +++ b/src/Utils/generics.ts @@ -230,14 +230,22 @@ export const bindWaitForConnectionUpdate = (ev: BaileysEventEmitter) => bindWait * utility that fetches latest baileys version from the master branch. * Use to ensure your WA connection is always on the latest version */ -export const fetchLatestBaileysVersion = async (options: RequestInit = {}) => { +export const fetchLatestBaileysVersion = async (options: RequestInit & { timeout?: number } = {}) => { const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts' try { - const response = await fetch(URL, { - dispatcher: options.dispatcher, - method: 'GET', - headers: options.headers - }) + const controller = new AbortController() + const timeout = setTimeout(() => controller.abort(), options.timeout ?? 5000) + 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 }) }