Repository navigation
fix(discord): stop queued reconnect exhaustion crash - #55991
Conversation
Greptile SummaryThis PR fixes a narrow race condition in the Discord gateway lifecycle: a Confidence Score: 5/5This PR is safe to merge; it fixes a real crash path with a minimal, targeted change and correct regression coverage. No P0 or P1 findings. The fix is correctly scoped to the buffered-drain branch only — live event handling is untouched, No files require special attention.
|
| Filename | Overview |
|---|---|
| extensions/discord/src/monitor/provider.lifecycle.ts | Removes the lifecycleStopping guard from the drainPendingGatewayErrors callback so buffered reconnect-exhausted events are always treated as graceful stops rather than thrown crashes. |
| extensions/discord/src/monitor/provider.lifecycle.test.ts | Flips the regression test from asserting a crash (rejects.toThrow) to asserting a clean resolution (resolves.toBeUndefined), and retains the runtimeError assertion to confirm the error is still logged. |
| CHANGELOG.md | Adds a changelog entry for the buffered reconnect-exhausted crash fix. |
Reviews (1): Last reviewed commit: "Merge branch 'main' into review/issue-ba..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ee491c80f
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Don't throw for expected shutdown events. `reconnect-exhausted` can be | ||
| // queued before teardown flips `lifecycleStopping`, so treat it as a | ||
| // graceful stop here and let the health monitor own reconnect behavior. | ||
| if (event.type === "disallowed-intents" || event.type === "reconnect-exhausted") { |
There was a problem hiding this comment.
Restrict queued reconnect-exhausted suppression to shutdown path
This change makes drainPendingGatewayErrors() treat every buffered reconnect-exhausted event as a graceful stop, even when the lifecycle is still starting and no shutdown/abort is in progress. In that startup-buffering scenario, runDiscordGatewayLifecycle() now returns instead of rejecting, so the channel restart loop in src/gateway/server-channels.ts does not run its .catch(...) path that records lastError, which hides a real reconnect exhaustion failure from runtime status and diagnostics while the account keeps restarting. Please gate this suppression to an explicit stop condition (e.g., abort/lifecycle teardown) rather than all buffered reconnect exhaustion events.
Useful? React with 👍 / 👎.
|
Nice fix — the Worth flagging: #55000 addresses the same crash at the root cause level by calling |
Summary
reconnect-exhaustedwas buffered before lifecycle teardown flippedlifecycleStopping.drainPendingGatewayErrors()now treats queuedreconnect-exhaustedthe same way as other expected shutdown events, and the lifecycle regression test now locks in graceful completion instead of a thrown crash.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
provider.lifecycle.tsonly suppressedreconnect-exhaustedwhenlifecycleStoppingwas already true, but the supervisor can drain a bufferedreconnect-exhaustedevent before teardown flips that flag.git blame, prior PR, issue, or refactor if known): earlier fixes in fix(discord): suppress expected reconnect-exhausted shutdown errors #55324 and fix(discord): guard gateway cleanup races #55373 covered adjacent shutdown/teardown races, but not the buffered pre-teardown drain path.Regression Test Plan (if applicable)
extensions/discord/src/monitor/provider.lifecycle.test.tsreconnect-exhaustedevent plus abort should resolve the lifecycle cleanly instead of throwing.drainPendingGatewayErrors()branch that was still crashing.User-visible / Behavior Changes
Discord stale-socket restarts no longer crash the full gateway when the reconnect-exhausted event was buffered just before teardown.
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
Steps
reconnect-exhaustedgateway event before teardown flipslifecycleStopping.Expected
Actual
Max reconnect attempts (0) reached after code 1005and crashed the process.Evidence
Attach at least one:
Human Verification (required)
pnpm test -- extensions/discord/src/monitor/provider.lifecycle.test.ts extensions/discord/src/monitor/gateway-supervisor.test.tsafter the patch.Review Conversations
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoFailure Recovery (if this breaks)
extensions/discord/src/monitor/provider.lifecycle.tsRisks and Mitigations
reconnect-exhaustedas a graceful stop could hide a real fatal queued reconnect exhaustion in this narrow pre-teardown path.