fix: add timeout to waitForWaConnection to prevent indefinite hangs#63037
fix: add timeout to waitForWaConnection to prevent indefinite hangs#63037mmcc9988 wants to merge 8 commits into
Conversation
Greptile SummaryAdds a configurable Confidence Score: 5/5Safe to merge — the fix is correct, backward-compatible, and follows established patterns in the file. All findings are P2 (a test for the new timeout path is missing but not blocking). The implementation is idempotent, handles cleanup on every exit path, and the timeoutMs=0 escape hatch correctly preserves old behavior. No files require special attention.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 006848c762
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b4c6a9557
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
220e0ea to
894a227
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 894a227a93
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Keep this PR open: current main still has a source-reproducible unbounded WhatsApp connection wait, and the branch now preserves the no-timeout QR/login path while adding bounded waits at startup call sites. It is not merge-ready yet because this external PR still has only mocked/unit proof for a compatibility- and availability-sensitive live WhatsApp startup change. Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. So I’m closing this here because the remaining work is already tracked in the canonical issue. Review detailsBest possible solution: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. Do we have a high-confidence way to reproduce the issue? Yes, at source level. A socket/event emitter that never emits connection.update with open or close leaves current-main waitForWaConnection pending, and the monitor/controller await that promise during startup. Is this the best way to solve the issue? Yes for the code shape, but not merge-ready yet. The maintainable fix is a central wait helper with opt-in bounded startup call sites and preserved no-timeout login compatibility; the remaining gap is real behavior proof. Security review: Security review cleared: The diff changes WhatsApp runtime timeout handling and tests only; no concrete secret, dependency, workflow, package, or supply-chain expansion was found. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 6486fc1c0dfb. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
If Baileys fails to emit a 'connection.update' event with either 'open' or 'close' status (e.g. due to network issues or internal errors), the waitForWaConnection promise hangs forever, blocking the entire monitor loop. Add a configurable timeout (default 60s) that rejects the promise and cleans up the event listener if no connection state is received in time. The timeout is backward-compatible as an optional parameter with a sensible default.
- Test that promise rejects with descriptive error after timeout - Test that event listener is cleaned up after timeout - Test that timer is cleared when connection opens before timeout
The 60s default broke the QR login flow in login-qr.ts, which calls waitForWaConnection without a timeout and expects to wait up to 3 minutes while the user scans. Change the default to 0 (wait forever, matching original behavior) and pass the 60s timeout explicitly at the monitor callsite where it's actually needed.
894a227 to
7c2437c
Compare
|
ClawSweeper applied the proposed close for this PR.
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Problem
waitForWaConnectionlistens for a Baileysconnection.updateevent with either'open'or'close'status, but has no timeout. If Baileys fails to emit either event (e.g. due to network issues, DNS resolution failures, or internal errors), the promise hangs indefinitely, blocking the entire WhatsApp monitor loop from reconnecting.Fix
Add a configurable
timeoutMsparameter (default 60s) that:The change is backward-compatible — the timeout parameter is optional with a sensible default. Callers that pass
0get the old behavior (wait forever).Testing
vi.fn().mockResolvedValue(undefined))closepath