fix(client): reconnect the gateway socket when switching servers #113
No reviewers
Labels
No labels
area:api
area:core
area:docs
area:infra
area:ux
dependencies
documentation
duplicate
good first issue
help wanted
invalid
question
rust
status:complete
status:partial
status:planned
type:bug
type:design
type:feature
type:infra
type:refactor
type:refactor
type:research
type:ux
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
icub3d/decentcom!113
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/gateway-server-switch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes live message updates silently dying after the first server switch.
Symptom
A chatbot reply (or any other user's message) never appeared in the client until the user clicked to another server and back — i.e. until a REST refetch. Verified server-side delivery was fine: a raw gateway socket subscribed to the channel received the
MESSAGE_CREATEbroadcasts instantly.Root cause
Switching servers runs
serverStore.connect(newAddress)→gateway.reconnect(), butGatewayClient.connect()returned early whenever any socket was open:That open socket is the one still connected to the previous server (nothing on the server-switch path ever calls
disconnect()— only account switches do). From then on everySUBSCRIBEwent down the stale socket and no live events from the current server arrived. REST fetches still worked, which is why switching away and back "fixed" it.Fix
Track the address each socket was dialed for (
socketAddress). Whenconnect()finds an open socket whose address no longer matches the store, it drops it via a newdropSocket()— detaching all handlers first so the abandoned socket's lateonclosecan't null out the replacement or schedule a spurious reconnect — and dials the new server. Same-address reconnects still reuse the open socket as before.Tests
New
gateway.test.ts(stubbed WebSocket): dials store address with token subprotocol, reuses open socket for same address, drops + redials on address change, survives a late close from the abandoned socket, subscribes to the current channel on open. Full client suite: 94 passed; eslint + tsc clean.🤖 Generated with Claude Code