If `Close` is called after the HTTP server has been closed, a goroutine currently leaks. ```go package main import ( "context" "net/http" "net/http/httptest" "go.uber.org/goleak" "nhooyr.io/websocket" ) func main() { done := make(chan struct{}) srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { conn, err := websocket.Accept(rw, r, nil) if err != nil { panic(err) } close(done) conn.Close(websocket.StatusNormalClosure, "") })) _, _, err := websocket.Dial(context.Background(), srv.URL, nil) if err != nil { panic(err) } <-done srv.Close() err = goleak.Find() if err != nil { panic(err) } } ```
Activity
kylecarbs commentedon Feb 20, 2022
Nevermind, it shouldn't. The connection should always send a closure so the opposing end doesn't timeout on the connection.
nhooyr commentedon Oct 19, 2023
Nah this is an issue. I forgot to respond. Glad I remembered this lol.
After Close() returns, you should be guaranteed that there are no more goroutines for the websocket. This is currently not the case.
[-]Close() should accept a context to allow for clean exits[/-][+]Close should guarantee no more goroutines[/+]main_test.go: Add to detect goroutine leaks
Ensure no goroutines leak after Close
nhooyr commentedon Oct 19, 2023
Fixed in dev.
Ensure no goroutines leak after Close in a cleaner way
wsjs: Ensure no goroutines leak after Close
wsjs: Ensure no goroutines leak after Close
wsjs: Ensure no goroutines leak after Close
wsjs: Ensure no goroutines leak after Close