Skip to content

fix(ws): add gateway close code 4013 (AckBackpressure) and mark as re…#24

Open
dogbonewish wants to merge 1 commit intofluxerjs:mainfrom
dogbonewish:fix/ack-backpressure-4013
Open

fix(ws): add gateway close code 4013 (AckBackpressure) and mark as re…#24
dogbonewish wants to merge 1 commit intofluxerjs:mainfrom
dogbonewish:fix/ack-backpressure-4013

Conversation

@dogbonewish
Copy link

@dogbonewish dogbonewish commented Mar 5, 2026

Description

The Fluxer gateway sends close code 4013 (ack_backpressure) when the session's
event acknowledgement buffer overflows (>4096 unacked events). This is a transient
condition and its safe to reconnect after, but shouldReconnectOnClose() doesn't include it, causing shards to silently die instead of auto-reconnecting.

This adds:

  • AckBackpressure: 4013 to GatewayCloseCodes
  • case 4013 to shouldReconnectOnClose() so that the shard reconnects automatically

Ref: fluxer_gateway/src/utils/constants.erl close_code_to_num(ack_backpressure) -> 4013

Type of change

  • Bug fix

Checklist

  • My code follows the project's style guidelines (run pnpm run lint)
  • I have run pnpm run build successfully
  • I have run pnpm run test successfully

Summary by CodeRabbit

  • Bug Fixes
    • Improved WebSocket connection reliability by adding automatic reconnection support for gateway acknowledgment backpressure scenarios. When the gateway indicates backpressure conditions during high-load periods, the system will now automatically reconnect, reducing service interruptions and enhancing connection stability. This ensures more consistent and reliable connectivity during demanding usage scenarios.

@vercel
Copy link

vercel bot commented Mar 5, 2026

@dogbonewish is attempting to deploy a commit to the blstmo's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 35cc5c6b-21ff-4d45-9648-bfce549610c9

📥 Commits

Reviewing files that changed from the base of the PR and between 99cce8e and b57de80.

📒 Files selected for processing (4)
  • .changeset/fix-ack-backpressure-4013.md
  • packages/ws/src/WebSocketShard.ts
  • packages/ws/src/utils/constants.test.ts
  • packages/ws/src/utils/constants.ts

📝 Walkthrough

Walkthrough

This pull request introduces support for WebSocket gateway close code 4013 (AckBackpressure) by adding the new code to the GatewayCloseCodes constant, integrating it into the shard reconnection logic to trigger automatic reconnection, and updating corresponding tests.

Changes

Cohort / File(s) Summary
Changeset Documentation
.changeset/fix-ack-backpressure-4013.md
Documents the addition of gateway close code 4013 support for automatic shard reconnection on ack backpressure.
Gateway Close Codes Constants
packages/ws/src/utils/constants.ts, packages/ws/src/utils/constants.test.ts
Adds AckBackpressure: 4013 enum member to GatewayCloseCodes and updates tests to assert the new code's value and inclusion in expected keys.
WebSocket Shard Reconnect Logic
packages/ws/src/WebSocketShard.ts
Adds handling for close code 4013 in shouldReconnectOnClose to trigger automatic reconnection on ack backpressure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐰 A hop, a skip, through gateway gates,
When 4013 code awaits,
No need to fret or hesitate—
The shard reconnects, resets its fate!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title concisely describes the main change: adding gateway close code 4013 (AckBackpressure) support and marking shards to reconnect on this code, which aligns with all the file changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant