File tree 1 file changed +10
-2
lines changed 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,15 @@ func (r *Runner) Init(scripts []codersdk.WorkspaceAgentScript) error {
97
97
// StartCron starts the cron scheduler.
98
98
// This is done async to allow for the caller to execute scripts prior.
99
99
func (r * Runner ) StartCron () {
100
- r .cron .Start ()
100
+ // cron.Start() and cron.Stop() does not guarantee that the cron goroutine
101
+ // has exited by the time the `cron.Stop()` context returns, so we need to
102
+ // track it manually.
103
+ err := r .trackCommandGoroutine (func () {
104
+ r .cron .Run ()
105
+ })
106
+ if err != nil {
107
+ r .Logger .Warn (context .Background (), "start cron failed" , slog .Error (err ))
108
+ }
101
109
}
102
110
103
111
// Execute runs a set of scripts according to a filter.
@@ -254,7 +262,7 @@ func (r *Runner) Close() error {
254
262
}
255
263
close (r .closed )
256
264
r .cronCtxCancel ()
257
- r .cron .Stop ()
265
+ <- r .cron .Stop (). Done ()
258
266
r .cmdCloseWait .Wait ()
259
267
return nil
260
268
}
You can’t perform that action at this time.
0 commit comments