Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f28220

Browse files
authored
fix(coderd): add timeout to websocket waitgroup on shutdown (coder#12754)
1 parent cfb484f commit 5f28220

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

coderd/coderd.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,23 @@ func (api *API) Close() error {
12851285
api.derpCloseFunc()
12861286
}
12871287

1288-
api.WebsocketWaitMutex.Lock()
1289-
api.WebsocketWaitGroup.Wait()
1290-
api.WebsocketWaitMutex.Unlock()
1288+
wsDone := make(chan struct{})
1289+
timer := time.NewTimer(10 * time.Second)
1290+
defer timer.Stop()
1291+
go func() {
1292+
api.WebsocketWaitMutex.Lock()
1293+
defer api.WebsocketWaitMutex.Unlock()
1294+
api.WebsocketWaitGroup.Wait()
1295+
close(wsDone)
1296+
}()
1297+
// This will technically leak the above func if the timer fires, but this is
1298+
// maintly a last ditch effort to un-stuck coderd on shutdown. This
1299+
// shouldn't affect tests at all.
1300+
select {
1301+
case <-wsDone:
1302+
case <-timer.C:
1303+
api.Logger.Warn(api.ctx, "websocket shutdown timed out after 10 seconds")
1304+
}
12911305

12921306
api.dbRolluper.Close()
12931307
api.metricsCache.Close()

0 commit comments

Comments
 (0)