Skip to content

fix(mercury): isolate reconnect generations - #24

Open
samtsai wants to merge 1 commit into
WebexCommunity:mainfrom
samtsai:codex/fix-mercury-reconnect-generation
Open

samtsai wants to merge 1 commit into
WebexCommunity:mainfrom
samtsai:codex/fix-mercury-reconnect-generation

Conversation

@samtsai

@samtsai samtsai commented Sep 14, 2026

Copy link
Copy Markdown

🚀 Description, Motivation, and Context

Fixes a Mercury reconnect race that can leave a replacement WebSocket connected but unable to receive events.

Each Mercury connection now owns its listener, heartbeat loop, pong handler, and lifecycle channels. A stale connection cannot clear the connected state of a newer connection or trigger a second reconnect. WebSocket writes are also serialized across authentication, heartbeat, and shutdown paths.

This preserves the existing public API and automatic reconnect behavior while making reconnect state generation-safe.

📖 Issues and Related PRs

No issue or related PR was supplied.

🖼 Screenshots

Not applicable; this change does not modify the UI.

🌮 How This Was Tested

  • Ran locally and verified
  • Created tests (unit and/or E2E)
  • Automated testing unnecessary (chores, doc updates, etc.)

Added a regression test that:

  • Accepts an initial Mercury connection and confirms authorization.
  • Closes the first connection to trigger automatic reconnect.
  • Verifies the replacement connection sends heartbeat pings.
  • Verifies the stale connection cannot mark the replacement disconnected.

Validation commands:

go test ./mercury
go test -race ./mercury
go test ./...
go vet ./...
git diff --check

Required Items Complete

  • Unit tests written
  • Integration tests written
  • Coverage verified
  • Functionally tested
  • Deployable to production
  • Uses feature flags
  • README updated
  • Build passes

Security

Not applicable. This change does not alter authentication, authorization, credentials, network endpoints, or stored data.

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