mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
fix: Race when shutting down and opening WebSockets (#576)
Adding to a WaitGroup while calling wait is a race condition. Surrounding this in a mutex should solve the problem. Since context is used for cancellation on all sockets, cleanup should occur properly. See: https://github.com/coder/coder/runs/5701221057?check_suite_focus=true#step:10:98
This commit is contained in:
@ -176,7 +176,11 @@ func New(options *Options) (http.Handler, func()) {
|
||||
})
|
||||
})
|
||||
r.NotFound(site.DefaultHandler().ServeHTTP)
|
||||
return r, api.websocketWaitGroup.Wait
|
||||
return r, func() {
|
||||
api.websocketWaitMutex.Lock()
|
||||
api.websocketWaitGroup.Wait()
|
||||
api.websocketWaitMutex.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// API contains all route handlers. Only HTTP handlers should
|
||||
@ -184,5 +188,6 @@ func New(options *Options) (http.Handler, func()) {
|
||||
type api struct {
|
||||
*Options
|
||||
|
||||
websocketWaitMutex sync.Mutex
|
||||
websocketWaitGroup sync.WaitGroup
|
||||
}
|
||||
|
Reference in New Issue
Block a user