You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
websocket.Conn.CloseNow() panics in WaitGroup.Wait #437
When CloseNow() is called by 2 goroutines, there is a race condition:
panic: sync: WaitGroup is reused before previous Wait has returned
goroutine 105321 [running]:
sync.(*WaitGroup).Wait(0xe33400?)
/src/sync/waitgroup.go:118 +0x74
nhooyr.io/websocket.(*Conn).CloseNow(0xc02d1e5860)
/.go/pkg/mod/nhooyr.io/websocket@v1.8.10/close.go:113 +0xcb
Original func
func (c *Conn) CloseNow() (err error) {
defer c.wg.Wait()
defer errd.Wrap(&err, "failed to close WebSocket")
if c.isClosed() {
return net.ErrClosed
}
...
}
Possible fix: move defer calls below isClosed()
func (c *Conn) CloseNow() (err error) {
if c.isClosed() {
return net.ErrClosed
}
defer c.wg.Wait()
defer errd.Wrap(&err, "failed to close WebSocket")
...
}
Activity
close.go: Rewrite how the library handles closing
nhooyr commentedon Apr 5, 2024
Thanks for reporting. I've fixed this in #427. Please review and let me know if you see anything else.
close.go: Rewrite how the library handles closing
nhooyr commentedon Apr 7, 2024
Sorry for the delay. Fixed by #427.