mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
fix(api): Allow workspace agent coordinate to report disconnect (#6152)
This commit is contained in:
committed by
GitHub
parent
6189035e98
commit
2dbe00ae44
@ -230,7 +230,11 @@ func New(options *Options) *API {
|
||||
staticHandler = httpmw.HSTS(staticHandler, options.StrictTransportSecurityCfg)
|
||||
|
||||
r := chi.NewRouter()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
api := &API{
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
|
||||
ID: uuid.New(),
|
||||
Options: options,
|
||||
RootHandler: r,
|
||||
@ -676,6 +680,11 @@ func New(options *Options) *API {
|
||||
}
|
||||
|
||||
type API struct {
|
||||
// ctx is canceled immediately on shutdown, it can be used to abort
|
||||
// interruptible tasks.
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
|
||||
*Options
|
||||
// ID is a uniquely generated ID on initialization.
|
||||
// This is used to associate objects with a specific
|
||||
@ -710,6 +719,8 @@ type API struct {
|
||||
|
||||
// Close waits for all WebSocket connections to drain before returning.
|
||||
func (api *API) Close() error {
|
||||
api.cancel()
|
||||
|
||||
api.WebsocketWaitMutex.Lock()
|
||||
api.WebsocketWaitGroup.Wait()
|
||||
api.WebsocketWaitMutex.Unlock()
|
||||
|
Reference in New Issue
Block a user