Skip to content

fix(client): wait until WebSocket is open before sending#615

Merged
dinwwwh merged 3 commits intomainfrom
fix/client/wait-until-websocket-open-before-send
Jun 7, 2025
Merged

fix(client): wait until WebSocket is open before sending#615
dinwwwh merged 3 commits intomainfrom
fix/client/wait-until-websocket-open-before-send

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Jun 7, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Ensured messages are only sent after the WebSocket connection is fully open, preventing premature message sending.
  • Tests

    • Improved test coverage to verify correct message handling when the WebSocket is not yet open and after it becomes open.

@vercel
Copy link
Copy Markdown

vercel bot commented Jun 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2025 1:10pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 7, 2025

"""

Walkthrough

The WebSocket client implementation was updated to ensure messages are only sent after the connection is open by introducing an awaitable promise. The options interface was extended to include the WebSocket's readyState. The test suite was enhanced to mock readyState and to verify that messages are not sent before the connection is established.

Changes

File(s) Change Summary
packages/client/src/adapters/websocket/link-websocket-client.ts Added readyState to options; implemented async send function that waits for WebSocket to open.
packages/client/src/adapters/websocket/rpc-link.test.ts Enhanced tests: mocked readyState, improved async assertions, and added test for connection wait.

Sequence Diagram(s)

sequenceDiagram
    participant Client as experimental_LinkWebsocketClient
    participant WS as WebSocket
    participant Peer as ClientPeer

    Client->>WS: Check readyState
    alt readyState is not OPEN
        WS-->>Client: 'open' event
    end
    Client->>Peer: Create with async send (waits for open)
    Peer->>WS: send(message) (after open)
Loading

Poem

In the warren, webs connect,
But rabbits wait—no hasty send!
Only when the doors are wide,
Do messages begin to glide.
Tests now hop to check the gate,
Ensuring all is open—great!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eae4e4b and 6a7e5e8.

📒 Files selected for processing (1)
  • packages/client/src/adapters/websocket/link-websocket-client.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/client/src/adapters/websocket/link-websocket-client.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint
  • GitHub Check: publish-commit
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Jun 7, 2025

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@615

@orpc/client

npm i https://pkg.pr.new/@orpc/client@615

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@615

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@615

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@615

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@615

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@615

@orpc/react

npm i https://pkg.pr.new/@orpc/react@615

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@615

@orpc/server

npm i https://pkg.pr.new/@orpc/server@615

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@615

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@615

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@615

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@615

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@615

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@615

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@615

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@615

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@615

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@615

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@615

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@615

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@615

commit: 6a7e5e8

Copy link
Copy Markdown

@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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f23895 and f15e36f.

📒 Files selected for processing (2)
  • packages/client/src/adapters/websocket/link-websocket-client.ts (1 hunks)
  • packages/client/src/adapters/websocket/rpc-link.test.ts (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint
🔇 Additional comments (5)
packages/client/src/adapters/websocket/link-websocket-client.ts (2)

7-7: LGTM! Interface correctly extended with readyState.

The addition of readyState to the interface is necessary for checking WebSocket connection state.


25-28: Excellent implementation of the core fix.

The async send function correctly waits for the WebSocket to be open before sending messages, which addresses the PR objective perfectly.

packages/client/src/adapters/websocket/rpc-link.test.ts (3)

10-10: LGTM! Mock properly updated for new interface requirements.

Adding readyState: 1 to the mock is necessary and appropriate for existing tests that expect immediate message sending.


27-27: Good test improvements for async behavior.

Making the promise assignment explicit and awaiting it ensures proper test completion with the new asynchronous send behavior.

Also applies to: 43-43


54-85: Excellent test coverage for the new functionality.

This test comprehensively validates the core fix by:

  • Setting up WebSocket in CONNECTING state (readyState: 0)
  • Verifying messages are deferred until the open event
  • Testing the complete request-response flow

The test structure is well-designed and thoroughly covers the new behavior.

@dinwwwh dinwwwh merged commit 8cebf6f into main Jun 7, 2025
8 checks passed
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.

1 participant