Skip to content

fix(inspect): remove dead websocket-disconnect eventBus cleanup - #1354

Merged
lklimek merged 3 commits into
v1.6-devfrom
fix/inspect-eventbus-panic
Jun 19, 2026
Merged

lklimek merged 3 commits into
v1.6-devfrom
fix/inspect-eventbus-panic

Conversation

@lklimek

@lklimek lklimek commented Jun 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The inspect RPC server's Handler registered a websocket OnDisconnect callback that called eventBus.UnsubscribeAll(...) on a local eventBus interface that was never assigned — always nil — so every websocket disconnect panicked the disconnect goroutine (recovered by net/http, but incorrect).

The inspect RPC exposes only query routes (block, tx, validators, tx_search, …) and registers no subscribe/unsubscribe/events endpoint, so there are never any per-client subscriptions to clean up on disconnect. The whole disconnect path was dead copy-paste from the full-node RPC handler.

Change

Remove the dead websocket-disconnect cleanup from internal/inspect/rpc/rpc.go: the eventBusUnsubscriber interface, the always-nil eventBus, the disconnect callback and its OnDisconnect registration, plus the now-unused pubsub import and wmLogger. The /websocket endpoint still serves the query routes; disconnects can no longer panic because there is no longer a disconnect callback.

🤖 Generated with Claude Code

Handler() declared eventBus as a nil interface but the websocketDisconnectFn
closure called UnsubscribeAll on it unconditionally, panicking the inspect RPC
server on every WebSocket disconnect. Added a nil guard since the inspect server
registers no subscribe routes and the eventBus is intentionally absent here.
Also adds TestHandlerWebsocketDisconnectNoPanic to catch regression.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@lklimek
lklimek requested a review from QuantumExplorer as a code owner June 17, 2026 11:58
@coderabbitai

coderabbitai Bot commented Jun 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

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5c24c782-6a34-49fa-b87c-00dd65ff9b34

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/inspect-eventbus-panic

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

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

@thepastaclaw

thepastaclaw commented Jun 17, 2026 •

Copy link
Copy Markdown

✅ Review complete (commit 216d2f2)

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Small, correct bug fix that prevents a nil-interface panic in the inspect RPC server's websocket disconnect callback. The guard is verified minimal and the regression test exercises a real disconnect path. Two optional nitpicks remain: the underlying eventBus variable is permanently nil so the closure is dead code, and the regression test's timing relies on leaktest's grace period rather than a deterministic handshake wait.

💬 2 nitpick(s)

1 additional finding(s) omitted (not in diff).

Comment thread internal/inspect/rpc/rpc_test.go Resolved
The inspect RPC exposes only query routes (no subscribe/unsubscribe/events),
so the always-nil eventBus and its UnsubscribeAll-on-disconnect closure were
unreachable dead code copied from the full-node handler; remove entirely instead
of guarding with a nil check.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@lklimek lklimek changed the title fix(inspect): prevent nil eventBus panic on websocket disconnect fix(inspect): remove dead websocket-disconnect eventBus cleanup Jun 17, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Incremental review at 6a67b8d: the prior nil-guard fix has been superseded by removing the dead OnDisconnect cleanup path entirely (eventBus interface/variable, closure, registration, pubsub import, wmLogger, and the regression test). Both prior nitpicks are resolved. Codex flags loss of regression coverage; kept as a low-severity nitpick since the bug class is structurally eliminated (no callback registered = nothing to panic).

💬 1 nitpick(s)

Comment on lines +55 to 56
wm := server.NewWebsocketManager(logger, routes, server.ReadLimit(rpcConfig.MaxBodyBytes))
mux.HandleFunc("/websocket", wm.WebsocketHandler)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: Inspect websocket disconnect path no longer exercised by any test

The PR's only behavior change is constructing the websocket manager without an OnDisconnect callback, and the regression test that opened /websocket and closed it was removed alongside the dead-code cleanup. The shared ws_handler already nil-checks onDisconnect (rpc/jsonrpc/server/ws_handler.go:199), so the original panic is structurally impossible here — but if a future contributor wires an OnDisconnect callback back in, there is no inspect-level test that would catch the same nil-deref pattern. A minimal handler-level test that dials /websocket and closes the connection would document the contract. Optional polish — not a blocker.

source: ['codex']

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 216d2f2 — Inspect websocket disconnect path no longer exercised by any test no longer present.

Auto-resolved by the review system based on the latest commit diff. If you believe this was closed in error, reopen the thread.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a panic on websocket disconnect in the inspect RPC server by removing a dead OnDisconnect cleanup path that attempted to unsubscribe via an always-nil event bus reference. The inspect RPC handler only exposes query routes and does not support event subscriptions, so the disconnect cleanup was both unused and unsafe.

Changes:

  • Removed the unused eventBusUnsubscriber interface and the uninitialized eventBus variable that could cause a nil-pointer panic on websocket disconnect.
  • Dropped the websocket disconnect callback registration (server.OnDisconnect(...)) from the inspect RPC websocket manager setup.
  • Cleaned up now-unused imports/variables related to pubsub/unsubscribe logging.

# Conflicts:
#	internal/inspect/rpc/rpc.go
@lklimek
lklimek enabled auto-merge (squash) June 19, 2026 08:39

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Cumulative re-review at 216d2f2. The PR's core change (removing the dead nil-eventBus OnDisconnect callback in inspect Handler) remains clean. The v1.6-dev merge pulled in a CORS websocket test whose comment+mitigation describe the very panic this PR eliminates, leaving the merged head internally inconsistent — carried as one new suggestion. Prior nitpick about untested disconnect path is now FIXED because the merged-in test exercises websocket open+close.

🟡 1 suggestion(s)

1 additional finding(s) omitted (not in diff).

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `internal/inspect/rpc/rpc_test.go`:
- [SUGGESTION] internal/inspect/rpc/rpc_test.go:33-38: Stale workaround comment describes the panic this PR removes
  TestHandlerWebsocketOriginPolicy (merged in from v1.6-dev) sets srv.Config.ErrorLog to io.Discard and justifies it as silencing 'a pre-existing nil eventBus panic in Handler's OnDisconnect callback (tracked separately, not part of this change).' At HEAD, internal/inspect/rpc/rpc.go:52-71 no longer registers any OnDisconnect callback and there is no eventBus field — that was the dead code this PR (commit 6a67b8d) removed. The panic the comment references cannot occur, the io.Discard ErrorLog mitigation masks nothing, and the `io` and `stdlog` imports exist only to support that dead mitigation. The comment also actively misleads future readers by asserting an unfixed bug that was in fact fixed by this same PR. Remove the comment, the ErrorLog override, and the two imports so the merge result matches the stated intent of #1354.

@lklimek
lklimek merged commit 66e9aa5 into v1.6-dev Jun 19, 2026
16 checks passed
@lklimek
lklimek deleted the fix/inspect-eventbus-panic branch June 19, 2026 08:55
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