fix(api): Allow workspace agent coordinate to report disconnect (#6152)

This commit is contained in:
Mathias Fredriksson
2023-02-10 20:23:02 +02:00
committed by GitHub
parent 6189035e98
commit 2dbe00ae44
2 changed files with 24 additions and 5 deletions

View File

@ -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()