Skip to content

Comments

fix: add WebSocket endpoint registration and message type tests (#20)#356

Merged
tac0turtle merged 7 commits intomainfrom
ws-compat_worker-2
Feb 23, 2026
Merged

fix: add WebSocket endpoint registration and message type tests (#20)#356
tac0turtle merged 7 commits intomainfrom
ws-compat_worker-2

Conversation

@tac0turtle
Copy link
Contributor

@tac0turtle tac0turtle commented Feb 23, 2026

Summary

Partially addresses #20. Fixes a missing /websocket endpoint registration bug and adds integration tests documenting current message type behavior.

Issue #20 asks: Different WebSocket message types (text, binary, close, ping, pong) should be handled properly per RFC 6455 section 11.8.

Critical bug found: pkg/rpc/server.go only called rpcserver.RegisterRPCFuncs() which registers HTTP endpoints and a JSON-RPC / handler but does NOT register a /websocket endpoint. WebSocket clients could not connect at all. Fixed by adding NewWebsocketManager + mux.HandleFunc("/websocket", wm.WebsocketHandler) matching CometBFT's node.go pattern.

What this PR adds:

  • /websocket endpoint registration (bug fix — WS was non-functional without this)
  • 7 end-to-end integration tests covering all RFC 6455 frame types
  • Documentation on startRPC explaining WebSocket handler setup and per-frame-type behavior

What remains for full #20 closure:

  • Binary frames (0x2) are not explicitly rejected — they fall through to JSON decode and produce a generic "error unmarshaling request" parse error instead of a clear "unsupported message type" response. Fixing this requires wrapping CometBFT's WebsocketManager with a custom handler that inspects the message type from NextReader() before JSON decoding, or contributing the fix upstream
  • OnDisconnect callback for subscription cleanup on connection close is not wired up

Bug details

startRPC() only called rpcserver.RegisterRPCFuncs() which registers HTTP endpoints and a JSON-RPC / handler, but does NOT register a /websocket endpoint. CometBFT's own node.go separately creates a WebsocketManager and registers it at /websocket. This was missing from ev-abci.

Current message type behavior (documented, not all fixed)

Frame type Behavior Status
Text (0x1) JSON-RPC request dispatched normally Working
Binary (0x2) JSON decode fails with generic parse error Documented, not improved
Close (0x8) Clean connection teardown via IsCloseError Working
Ping (0x9) Pong sent via gorilla/websocket handler Working
Pong (0xA) Read deadline reset via SetPongHandler Working

Related: #18, #17

Test plan

  • make test passes with race detection
  • make lint passes with zero warnings
  • All 7 new integration tests pass
  • /websocket endpoint verified functional

🤖 Generated with Claude Code

tac0turtle and others added 3 commits February 23, 2026 15:20
Automatically adds newly opened issues to the EVStack Evolve
project board (orgs/evstack/projects/7).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tests (#20)

Critical fix: RegisterRPCFuncs does not register a WebSocket endpoint.
ev-abci was missing /websocket — clients could not connect via WebSocket at
all. Fix adds an explicit WebsocketManager registration in startRPC.

Documentation added to startRPC explaining RFC 6455 §11.8 message type
handling as delegated to CometBFT's wsConnection (gorilla/websocket).

New pkg/rpc/server_test.go with 7 integration tests:
- TestWebSocket_TextValidJSON: health request over WS returns success
- TestWebSocket_TextInvalidJSON: malformed JSON yields parse error (-32700)
- TestWebSocket_BinaryFrame: binary frames yield parse error, not crash
- TestWebSocket_CloseFrame: normal close (1000) closes connection cleanly
- TestWebSocket_PingPong: server-initiated pings received within timeout
- TestWebSocket_LargeMessage: exceeding read limit yields CloseMessageTooBig
- TestRPCServer_WebSocketEndpointRegistered: end-to-end /websocket works

Note: client-initiated ping test uses server-initiated pings instead to
avoid a pre-existing data race in CometBFT's ws_handler.go (writeRoutine
sets SetPingHandler concurrent with readRoutine's first advanceFrame call).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
IsUnexpectedCloseError(err, 1009) returns true when the code is NOT
1009, so the OR with IsCloseError made the assertion pass for any close
frame. Replace with IsCloseError(err, CloseMessageTooBig) alone to
enforce the specific code 1009.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tac0turtle tac0turtle requested a review from a team as a code owner February 23, 2026 15:23
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tac0turtle, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug preventing WebSocket clients from connecting to the RPC server by correctly registering the /websocket endpoint. It significantly enhances the robustness and reliability of WebSocket communication by introducing a suite of integration tests that validate handling of various message types, connection lifecycle, and error conditions. The changes ensure that the RPC server's WebSocket functionality aligns with expected behavior and RFC standards.

Highlights

  • WebSocket Endpoint Registration: The missing /websocket endpoint registration in pkg/rpc/server.go was fixed by adding NewWebsocketManager and mux.HandleFunc("/websocket", wm.WebsocketHandler), enabling WebSocket client connections.
  • WebSocket Integration Tests: Seven new end-to-end integration tests were added in pkg/rpc/server_test.go to cover various WebSocket message types and scenarios, including text, binary, close, ping/pong, and large messages.
  • WebSocket Documentation: Comprehensive documentation was added to the startRPC function, detailing WebSocket support, RFC 6455 section 11.8, and how different message types are handled.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • pkg/rpc/server.go
    • Added detailed comments explaining WebSocket support and message type handling in startRPC.
    • Integrated rpcserver.NewWebsocketManager and registered the /websocket handler to enable WebSocket connections.
  • pkg/rpc/server_test.go
    • Introduced a new test file containing end-to-end integration tests for WebSocket functionality.
    • Implemented tests for valid and invalid JSON text frames, binary frames, close frames, ping/pong mechanisms, and large messages.
    • Added a test to verify the successful registration and functionality of the /websocket endpoint on a running RPC server.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/add-to-project.yml
Activity
  • make test passed with race detection.
  • make lint passed with zero warnings.
  • All 7 new integration tests passed.
  • The WebSocket endpoint was verified to be functional.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a critical bug where the WebSocket endpoint was not being registered, preventing clients from connecting. The fix in pkg/rpc/server.go is correct and follows the established pattern from CometBFT. The addition of extensive integration tests in pkg/rpc/server_test.go is excellent, providing comprehensive coverage for various WebSocket message types and scenarios, which significantly improves the robustness of the RPC server. The code quality is high, and the new documentation is clear and helpful. I have one minor suggestion to improve maintainability in the new test file.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

utACK.

go mod tidy moves gorilla/websocket from indirect to direct now that
the WebSocket test code imports it explicitly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tac0turtle tac0turtle enabled auto-merge (squash) February 23, 2026 18:41
@tac0turtle tac0turtle disabled auto-merge February 23, 2026 18:48
tac0turtle and others added 2 commits February 23, 2026 19:50
Without OnDisconnect, disconnected WebSocket clients leave dangling
subscriptions on the EventBus. Pass the EventBus to RPCServer so the
WebSocket manager can call UnsubscribeAll on disconnect, matching
CometBFT's node.go pattern. Also set ReadLimit from RPC config.

Closes #18

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that when a WebSocket client subscribes to events and then
disconnects, the OnDisconnect callback fires and removes all
subscriptions for that client from the EventBus.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tac0turtle tac0turtle enabled auto-merge (squash) February 23, 2026 18:53
@tac0turtle tac0turtle merged commit ba94ff1 into main Feb 23, 2026
18 checks passed
@tac0turtle tac0turtle deleted the ws-compat_worker-2 branch February 23, 2026 19:33
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.

2 participants