Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix WebSocket serialization #1425

Merged
merged 7 commits into from
Jan 12, 2024
Merged

fix WebSocket serialization #1425

merged 7 commits into from
Jan 12, 2024

Conversation

tzdybal
Copy link
Member

@tzdybal tzdybal commented Jan 1, 2024

Unit test was updated to assert valid encoding of data. Hacky approach to fix the issue is not working. Replacing normal JSON serialization with JSON RPC serialization is required, but there still is an issue.

Overview

Draft for visibility. CC: @Manav-Aggarwal

Relates to: #1268

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

Summary by CodeRabbit

  • New Features

    • Enhanced WebSocket connection handling in JSON-RPC services.
  • Bug Fixes

    • Improved subscription response encoding in JSON-RPC.
  • Refactor

    • Updated WebSocket-related code to improve RPC request management.
  • Tests

    • Altered test cases to reflect new JSON unmarshalling approach.

Unit test was updated to assert valid encoding of data.
Hacky approach to fix the issue is not working. Replacing normal JSON serialization with JSON RPC serialization is required, but there still is an issue.
Copy link
Contributor

coderabbitai bot commented Jan 1, 2024

Walkthrough

The recent update involves enhancing the JSON RPC handling over WebSocket connections in a Go application. A new field has been added to manage the RPC requests more effectively, and there are improvements in the subscription function to better encode and write responses. The changes reflect a focus on more robust and efficient WebSocket communication for RPC services.

Changes

File Path Change Summary
rpc/json/handler.go Assigned codecReq to wsConn when not nil.
rpc/json/service.go Included new packages and updated the Subscribe function.
rpc/json/ws.go Added codecReq field to wsConn type.
rpc/json/ws_test.go Updated unmarshalling logic using jsonrpc and cmjson.

Poem

In the realm of code where data streams flow,
A rabbit hopped in, with updates in tow.
Through webs of sockets, messages dance with zest,
Our furry friend's work passes the WebSocket test. 🐰✨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@tzdybal
Copy link
Member Author

tzdybal commented Jan 1, 2024

The last commit might actually fix the issue.

Copy link

codecov bot commented Jan 11, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (9163b34) 51.56% compared to head (3f1487a) 51.66%.

Files Patch % Lines
rpc/json/service.go 66.66% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1425      +/-   ##
==========================================
+ Coverage   51.56%   51.66%   +0.09%     
==========================================
  Files          48       48              
  Lines        6469     6484      +15     
==========================================
+ Hits         3336     3350      +14     
  Misses       2789     2789              
- Partials      344      345       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

rpc/json/service.go Outdated Show resolved Hide resolved
@gupadhyaya gupadhyaya marked this pull request as ready for review January 11, 2024 11:31
@gupadhyaya gupadhyaya changed the title WIP: fix WebSocket serialization fix WebSocket serialization Jan 11, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fc88adc and ca64da9.
Files selected for processing (4)
  • rpc/json/handler.go (1 hunks)
  • rpc/json/service.go (2 hunks)
  • rpc/json/ws.go (1 hunks)
  • rpc/json/ws_test.go (2 hunks)
Additional comments: 5
rpc/json/ws_test.go (2)
  • 12-13: The addition of new imports cmjson and jsonrpc aligns with the PR's objective to switch to JSON RPC serialization. Ensure that these packages are used consistently throughout the codebase for JSON operations.

  • 69-73: The unmarshalling logic has been updated to use jsonrpc.Response and cmjson.Unmarshal instead of directly unmarshalling to cmtypes.EventDataNewBlock. This change is consistent with the PR's goal to use JSON RPC serialization. However, ensure that the EventDataNewBlock structure is compatible with the new unmarshalling process and that all necessary fields are correctly populated.

rpc/json/ws.go (1)
  • 16-19: The addition of the codecReq field to the wsConn type is a significant change that likely affects the handling of RPC requests over WebSocket connections. This change should be carefully tested to ensure that it does not introduce any regressions or unexpected behavior, especially since WebSocket connections can be sensitive to changes in serialization and deserialization logic.
rpc/json/service.go (2)
  • 4-4: The addition of the bytes package is likely used for buffer operations, which is a common requirement when dealing with serialization and deserialization. This change seems appropriate for the task at hand.

  • 108-126: The Subscribe function has been modified to handle encoding and writing responses differently. It now uses a codecReq which can be either from the wsConn or a new JSON RPC codec request. This change is consistent with the PR's goal to use JSON RPC serialization. However, it's crucial to ensure that the subscription logic correctly handles the new serialization format and that the data sent over the WebSocket connection is correctly encoded and decoded.

Verification successful

The review comment's concern about ensuring that the subscription logic correctly handles the new serialization format and that the data sent over the WebSocket connection is correctly encoded and decoded is addressed by the TestWebSockets function in the ws_test.go file. This test checks the WebSocket functionality, including the subscription logic, and verifies that messages are properly serialized and deserialized using the new JSON RPC serialization format.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the subscription logic correctly handles the new serialization format.
rg --type go "func Test.*Subscribe.*" --files-with-matches | xargs -I {} go test {}

Length of output: 89



Script:

#!/bin/bash
# First, let's find if there are any tests for the Subscribe function.
rg --type go "func Test.*Subscribe.*" --files-with-matches

Length of output: 60


Script:

#!/bin/bash
# Additionally, let's check if there are any tests related to WebSocket serialization specifically.
rg --type go "func Test.*WebSocket.*" --files-with-matches

Length of output: 80



Script:

#!/bin/bash
# Let's examine the contents of the ws_test.go file to understand how it tests the WebSocket serialization.
cat rpc/json/ws_test.go

Length of output: 2474

rpc/json/handler.go Show resolved Hide resolved
@gupadhyaya gupadhyaya added this pull request to the merge queue Jan 12, 2024
Merged via the queue into main with commit ff4a2d4 Jan 12, 2024
19 checks passed
@gupadhyaya gupadhyaya deleted the tzdybal/ws_writers branch January 12, 2024 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants