fix(whatsapp): add timeout to fetchLatestBaileysVersion to prevent permanent disconnect wedge - #77298
Closed
JonthanaHanh wants to merge 1 commit into
Closed
Conversation
…rmanent disconnect wedge The WhatsApp bridge can get permanently disconnected after a server-side disconnect (stream:error 503) when the reconnect path calls `fetchLatestBaileysVersion()` — a plain fetch() to raw.githubusercontent.com with no timeout. If the connection stalls, the fetch hangs forever. The bridge logs "Reconnecting in 3s..." once then goes silent; the Express server keeps serving 503 to the gateway indefinitely. Fixes NousResearch#77268 Changes: - Add `fetchWithTimeout()` helper that races an async function against a configurable timeout (default 15s, overridable via WHATSAPP_VERSION_FETCH_TIMEOUT_MS env var) - Wrap `fetchLatestBaileysVersion()` in `fetchWithTimeout()` so stalled version fetches fail fast instead of hanging forever - Wrap all `startSocket()` call sites with `.catch()` to prevent unhandled promise rejections (fatal on modern Node.js)
13 tasks
Collaborator
|
Closing as duplicate of #77337 (salvage of #77270 by the same author @ATran28). The salvage PR is the more complete version — includes cached version fallback, reconnect error handling with retry, and 6 regression tests. Your |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #77268
The WhatsApp bridge can get permanently disconnected after a server-side disconnect (stream:error 503) when the reconnect path calls
fetchLatestBaileysVersion()— a plainfetch()toraw.githubusercontent.comwith no timeout. If the connection stalls, the fetch hangs forever. The bridge logs "Reconnecting in 3s..." once then goes silent; the Express server keeps serving 503 to the gateway indefinitely (observed for 27+ hours in the field).Root Cause
Two issues in
scripts/whatsapp-bridge/bridge.js:fetchLatestBaileysVersion()has no timeout — it's a plainfetch()toraw.githubusercontent.comthat can hang indefinitely on network stalls. NoAbortSignalis passed and noPromise.racewraps it.setTimeout(startSocket, 3000)creates an unhandled promise rejection —startSocket()is async, so calling it fromsetTimeoutreturns a promise that's never.catch()-ed. On modern Node.js, unhandled rejections are fatal.Changes
fetchWithTimeout()helper that races an async function against a configurable timeout (default 15s, overridable viaWHATSAPP_VERSION_FETCH_TIMEOUT_MSenv var)fetchLatestBaileysVersion()infetchWithTimeout()so stalled version fetches fail fast instead of hanging foreverstartSocket()call sites with.catch()to prevent unhandled promise rejections (fatal on modern Node.js)Test Plan
node --check scripts/whatsapp-bridge/bridge.jspasses