Repository navigation
fix(inspect): remove dead websocket-disconnect eventBus cleanup - #1354
Conversation
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]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
✅ Review complete (commit 216d2f2) |
thepastaclaw
left a comment
There was a problem hiding this comment.
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).
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]>
thepastaclaw
left a comment
There was a problem hiding this comment.
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)
| wm := server.NewWebsocketManager(logger, routes, server.ReadLimit(rpcConfig.MaxBodyBytes)) | ||
| mux.HandleFunc("/websocket", wm.WebsocketHandler) |
There was a problem hiding this comment.
💬 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']
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
eventBusUnsubscriberinterface and the uninitializedeventBusvariable 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
thepastaclaw
left a comment
There was a problem hiding this comment.
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.
Summary
The inspect RPC server's
Handlerregistered a websocketOnDisconnectcallback that calledeventBus.UnsubscribeAll(...)on a localeventBusinterface 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 nosubscribe/unsubscribe/eventsendpoint, 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: theeventBusUnsubscriberinterface, the always-nileventBus, the disconnect callback and itsOnDisconnectregistration, plus the now-unusedpubsubimport andwmLogger. The/websocketendpoint still serves the query routes; disconnects can no longer panic because there is no longer a disconnect callback.🤖 Generated with Claude Code