Skip to content

fix: auto-reconnect websocket after unexpected close (#18) - #376

Open
slsgzs-cloud wants to merge 1 commit into
Bitcoindefi:mainfrom
slsgzs-cloud:fix/auto-reconnect
Open

slsgzs-cloud wants to merge 1 commit into
Bitcoindefi:mainfrom
slsgzs-cloud:fix/auto-reconnect

Conversation

@slsgzs-cloud

@slsgzs-cloud slsgzs-cloud commented Sep 17, 2026

Copy link
Copy Markdown

/attempt #743

Summary

Fixes #18.

The bug

When the websocket dropped, socket.onclose only emitted a "Conexion cerrada."
status and never tried again. The player was stranded with a dead connection and
had to reload the page and re-pick a character.

The fix

useGameSession now schedules a delayed reconnection whenever the socket closes,
driven by a new reconnectAttempt state that is a dependency of the connection
useEffect:

  • Up to RECONNECT_MAX_ATTEMPTS (5) retries, with exponential backoff
    (1s, 2s, 4s, 8s, 16s).
  • Each retry bumps reconnectAttempt, which re-runs the effect and opens a fresh
    socket. When the retry budget is exhausted the status stays at
    "Conexion cerrada." with no further retry, so a genuinely dead connection
    cannot produce a retry storm.
  • The budget resets to 0 in a small effect keyed on the session key, so starting
    a new game (a different character/account combination) always begins with a
    full set of retries.
  • The pending timer is cleared in the effect cleanup, so switching sessions or
    disconnecting never leaves a stale reconnect scheduled.
  • Retries only fire for the current socket/session instance (the existing
    isCurrentSocketInstance + activeSessionKeyRef guards), so a stale socket
    closing after a session switch cannot trigger a spurious reconnect.

Files changed: frontend/components/game/session/useGameSession.ts

@gitar-bot

gitar-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

Important

You are using the Gitar free plan. Upgrade to unlock code review, CI analysis, auto-apply, custom automations, and more.

Gitar

@slsgzs-cloud slsgzs-cloud changed the title probe fix: auto-reconnect websocket after unexpected close (#18) Sep 17, 2026
@slsgzs-cloud slsgzs-cloud reopened this Sep 17, 2026
@slsgzs-cloud

Copy link
Copy Markdown
Author

Hi maintainers! This PR is mergeable and clean. It fixes a bounty issue worth $50. Would appreciate a review.

@slsgzs-cloud

Copy link
Copy Markdown
Author

Hi @Rodrigoue9 @leocagli — PR #376 fixes Issue #18 (50 USD bounty). It is mergeable and clean. Could you review when you have a moment? Thank you!

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.

No hay reconexion automatica: si se corta la conexion hay que recargar la pagina

1 participant