Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Deadlocks due to CloseRead #429

Closed
Closed
Labels
Milestone
@creker

Description

@creker

nhooyr.io/websocket v1.8.10

The library uses deferdefer wg.Wait() in multiple functions and that causes calls to deadlock instead of properly shutting down when connection is terminated.

One possible situation is this:

  1. The server callsCloseRead
  2. The Client sends some message
  3. Goroutine inCloseRead unblocks fromReader(ctx) and callsClose
  4. Close blocks ondefer c.wg.Wait() but it can't succeed due toCloseRead callingwg.Add(1) and expecting it to be decremented withdefer wg.Done() on exit fromCloseRead. ButCloseRead cannot exit due toClose blocking. We have a deadlock and a goroutine leak. Context is never cancelled either which means all the other code that interacts with websocket also can't properly exit.

Switching to manually callingRead in a separate goroutine and cancelling context from it solves this problem. Basically, you have to reimplementCloseRead but without blocking on waitGroup

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp