mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
fix: Use sync.WaitGroup to await hijacked HTTP connections (#337)
WebSockets hijack the HTTP connection from the server, causing server.Close() to not wait for these connections to fully cleanup. This adds a global wait-group to the coderd API, which ensures all WebSocket HTTP handlers have properly exited before returning.
This commit is contained in:
@ -55,7 +55,7 @@ func New(t *testing.T) *codersdk.Client {
|
||||
})
|
||||
}
|
||||
|
||||
handler := coderd.New(&coderd.Options{
|
||||
handler, closeWait := coderd.New(&coderd.Options{
|
||||
Logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
|
||||
Database: db,
|
||||
Pubsub: pubsub,
|
||||
@ -69,7 +69,10 @@ func New(t *testing.T) *codersdk.Client {
|
||||
srv.Start()
|
||||
serverURL, err := url.Parse(srv.URL)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(srv.Close)
|
||||
t.Cleanup(func() {
|
||||
srv.Close()
|
||||
closeWait()
|
||||
})
|
||||
|
||||
return codersdk.New(serverURL)
|
||||
}
|
||||
|
Reference in New Issue
Block a user