Skip to content

fix(rpc): stop resubscribing subscription IDs as queries after reconnect - #1623

Draft
Claudius-Maginificent wants to merge 2 commits into
devfrom
fix/rpc-ws-stale-subscription-alias
Draft

Claudius-Maginificent wants to merge 2 commits into
devfrom
fix/rpc-ws-stale-subscription-alias

Conversation

@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator

TL;DR: After a WebSocket reconnect, the HTTP RPC client re-sent a bogus empty subscription that the node rejects, and then retried every second forever, stalling event delivery and filling logs with WS error.

User story

As a developer using rpc/client/http to subscribe to node events, directly or through the light client proxy, I want my subscriptions restored cleanly when the connection to the node drops and comes back, so events keep flowing without errors.

Scenario

Base flow

An application subscribes to node events (for example new blocks) through the HTTP RPC client. The node restarts or the network blips, and the client reconnects.

Actual behavior

Besides each query, the client stored the subscription ID from incoming events as an extra subscription key. Tenderdash sends events with an empty subscription ID, so after the first event the client tracked an extra key "". On every reconnect it sent subscribe "", which the node rejects (failed to parse query: offset 0: EOF). Each rejection makes the client wait a second and resubscribe everything again, so the loop never ends: events are delayed and WS error is logged every second. Upstreams that do send subscription IDs leaked one entry per reconnect and later resubscribed those IDs as queries.

Expected behavior

After a reconnect, the client resubscribes exactly the queries it was asked to subscribe to, and events keep arriving with no errors.

Detailed discussion

What was done

  • rpc/client/http/ws.go: subscriptions are tracked by query only. Removed the id field, the ID alias written by eventListener (also its only map write under RLock), the alias delete in Unsubscribe, and the alias skip in redoSubscriptionsAfter. Nothing looked subscriptions up by ID: event delivery is keyed by result.Query, and subscribers still receive SubscriptionID in each event unchanged. No exported API changes.
  • rpc/client/http/ws_reconnect_test.go: regression test against the node's real subscribe handler (real EventBus and rpccore routes behind rpcserver.NewWebsocketManager, with the node's OnDisconnect cleanup). Across three sessions with two forced reconnects it requires that each session still delivers events and that no WS error is logged.

Testing

  • The new test fails 3/3 on dev (logged failed to parse query: offset 0: EOF, or no resubscription on the new session) and passes repeatedly with the fix under -race, including a separate check against an upstream that assigns a new ID per session.
  • ./rpc/client/http/, ./rpc/client/, ./light/proxy/ and ./light/rpc/ pass with -race; gofmt, go vet and golangci-lint --new-from-rev=origin/dev are clean.
  • Reviewed by an independent reviewer; no blocking findings.

Breaking changes

None.

Prior work

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

lklimek and others added 2 commits November 17, 2026 10:26
wsEvents stored each event's subscription ID as an extra key in its
subscription map, and resubscribed every key on reconnect except one
equal to the subscription's latest ID. Tenderdash sends events without a
subscription ID, so the empty key was resubscribed as a query: the node
rejected it, and each rejection made the event loop resubscribe again a
second later, stalling event delivery. Upstreams sending fresh IDs per
session leaked one key per reconnect, resubscribed the same way.

Nothing looks subscriptions up by ID, so drop the ID keys; the alias
write was also the event loop's only map write under a read lock.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thepastaclaw

Copy link
Copy Markdown

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit 69cb77a. Normal review starts when eligible; priority review starts as soon as a slot is available.

This branch has not been deployed

No deployments
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.

3 participants