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

Switch websocket library #20

Merged
merged 1 commit into from
Feb 18, 2025
Merged

Switch websocket library #20

merged 1 commit into from
Feb 18, 2025

Conversation

whywaita
Copy link
Owner

@whywaita whywaita commented Feb 17, 2025

x/net/websocket is deprecated in golang/go#18152

Summary by CodeRabbit

  • Chores

    • Updated underlying dependencies for enhanced stability.
  • Bug Fixes

    • Improved WebSocket connection handling with more robust error reporting and graceful termination, ensuring smoother real-time communications.

Copy link

coderabbitai bot commented Feb 17, 2025

Walkthrough

The pull request updates the project's dependency management and WebSocket handling. The go.mod file now includes the github.com/coder/websocket v1.8.12 dependency while moving golang.org/x/net v0.35.0 to indirect. In addition, the WebSocket code in the server module has been updated to switch from the old library to the new one, with changes to the import, connection acceptance, error handling, and message sending through a refined control flow that listens for cancellation and notification events.

Changes

Files Change Summary
go.mod - Added dependency: github.com/coder/websocket v1.8.12
- Reclassified golang.org/x/net v0.35.0 as an indirect dependency
pkg/.../server_ws.go - Switched WebSocket import from golang.org/x/net/websocket to github.com/coder/websocket
- Updated connection acceptance, error handling, and message sending API

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant S as Server (ws function)
    participant NP as Notifier (notifyCh)
    participant CTX as Context

    C->>S: Request WebSocket Connection
    S->>websocket: Accept Connection
    alt Acceptance Error
        S->>C: Return error message
    else Connection Established
        S->>S: Defer wsConn.Close
        par Listen for signals
            CTX-->>S: Cancel signal
            NP-->>S: Notification signal
        end
        S->>S: Invoke sendPlayer(wsConn)
        S->>C: Send message via WebSocket
    end
Loading

Possibly related PRs

  • whyywaita/rfid-poker#9: Addresses similar dependency changes in go.mod by managing the classification of dependencies.

Poem

I'm a rabbit hopping through the code,
With new webs spun in a swift, light mode.
Direct dependencies now proudly shine,
Indirect ones nestle neatly in line.
In each connection, a gentle hop so free—
Celebrating change with carrot-powered glee!

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 golangci-lint (1.62.2)

Error: can't load config: the Go language version (go1.23) used to build golangci-lint is lower than the targeted Go version (1.24.0)
Failed executing command with error: can't load config: the Go language version (go1.23) used to build golangci-lint is lower than the targeted Go version (1.24.0)

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • Generate unit testing code for this file.
    • 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 generate unit testing code 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 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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link

@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: 0

🧹 Nitpick comments (1)
pkg/server/server_ws.go (1)

38-40: Consider restricting WebSocket origin patterns.

The current setting OriginPatterns: []string{"*"} allows connections from any origin, which might pose security risks. Consider restricting this to specific trusted origins.

-		OriginPatterns: []string{"*"},
+		OriginPatterns: []string{"https://*.example.com", "http://localhost:*"},
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4345af4 and 3e32260.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • go.mod (2 hunks)
  • pkg/server/server_ws.go (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (4)
pkg/server/server_ws.go (3)

12-14: LGTM! Clean switch to the new WebSocket library.

The import changes and comment update accurately reflect the switch from the deprecated x/net/websocket to github.com/coder/websocket.

Also applies to: 18-18


46-62: LGTM! Well-structured event loop with proper context handling.

The implementation correctly handles both context cancellation and notifications, with appropriate error logging.


77-79: LGTM! Clean implementation of WebSocket message writing.

The new implementation properly uses context and correctly specifies the message type, with appropriate error handling.

go.mod (1)

3-3: ⚠️ Potential issue

❌ Incorrect review comment

Fix the Go version.

The specified Go version 1.24.0 appears to be incorrect as it's not released yet.

Let's verify the latest Go version:

Please update to the latest stable version of Go.


🌐 Web query:

What is the latest version of Go?

💡 Result:

The latest stable version of Go is 1.24.0, released on February 11, 2025[4]. This follows the standard Go release cycle of major versions every 6 months.

Key details about recent releases:

Version Release Date Support Status
1.24 2025-02-11 Current stable release
1.23 2024-08-13 Supported until 1.25
1.22 2024-02-06 Supported until 1.24

The Go team maintains support for the two most recent major releases[1][4]. Current active maintenance includes security fixes and critical bug patches for both Go 1.24 and Go 1.23.

To install the latest version:

go install golang.org/dl/go1.24@latest
go1.24 download

Recent minor revisions include security updates to packages like crypto/elliptic and net/http in versions 1.23.x[4]. The latest patch version as of February 17, 2025 is Go 1.24.0 with no subsequent minor revisions yet released[4].

Citations:


Verified: The Go version in go.mod is correct

After checking the latest stable release information, Go 1.24.0 is indeed the current stable version (released on February 11, 2025). The version specified in go.mod (line 3) is accurate, so no changes are needed.

Likely an incorrect or invalid review comment.

@whywaita whywaita merged commit cbff88e into main Feb 18, 2025
3 checks passed
@whywaita whywaita deleted the feat/switch-websocket-library branch February 18, 2025 03:02
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