mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix(agent/agentscripts): track cron run and wait for cron stop (#10388)
Fixes #10289
This commit is contained in:
committed by
GitHub
parent
1a2aea3a6b
commit
09f7b8e88c
@@ -97,7 +97,15 @@ func (r *Runner) Init(scripts []codersdk.WorkspaceAgentScript) error {
|
||||
// StartCron starts the cron scheduler.
|
||||
// This is done async to allow for the caller to execute scripts prior.
|
||||
func (r *Runner) StartCron() {
|
||||
r.cron.Start()
|
||||
// cron.Start() and cron.Stop() does not guarantee that the cron goroutine
|
||||
// has exited by the time the `cron.Stop()` context returns, so we need to
|
||||
// track it manually.
|
||||
err := r.trackCommandGoroutine(func() {
|
||||
r.cron.Run()
|
||||
})
|
||||
if err != nil {
|
||||
r.Logger.Warn(context.Background(), "start cron failed", slog.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
// Execute runs a set of scripts according to a filter.
|
||||
@@ -254,7 +262,7 @@ func (r *Runner) Close() error {
|
||||
}
|
||||
close(r.closed)
|
||||
r.cronCtxCancel()
|
||||
r.cron.Stop()
|
||||
<-r.cron.Stop().Done()
|
||||
r.cmdCloseWait.Wait()
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user