From a1def8c2c0494e2ed44e210eb924859be926cafa Mon Sep 17 00:00:00 2001 From: Renato Alcara Date: Sun, 1 Mar 2026 09:27:16 -0300 Subject: [PATCH] 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. Co-Authored-By: Claude Opus 4.6 --- src/Utils/generics.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Utils/generics.ts b/src/Utils/generics.ts index d328a58d..dec4653c 100644 --- a/src/Utils/generics.ts +++ b/src/Utils/generics.ts @@ -230,14 +230,18 @@ 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 controller = new AbortController() + const timeout = setTimeout(() => controller.abort(), options.timeout ?? 5000) const response = await fetch(URL, { dispatcher: options.dispatcher, method: 'GET', - headers: options.headers + headers: options.headers, + signal: controller.signal }) + clearTimeout(timeout) if (!response.ok) { throw new Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, { statusCode: response.status }) }