Skip to content

Commit a6ea995

Browse files
authored
fix: Return from update loop when job completes (coder#1121)
Update was running forever, which stopped jobs from timing out unless a restart occurred. This also fixes complete properly reporting an error.
1 parent d448763 commit a6ea995

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

provisionerd/provisionerd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ func (p *Server) acquireJob(ctx context.Context) {
247247
func (p *Server) runJob(ctx context.Context, job *proto.AcquiredJob) {
248248
shutdown, shutdownCancel := context.WithCancel(ctx)
249249
defer shutdownCancel()
250+
251+
complete, completeCancel := context.WithCancel(ctx)
252+
defer completeCancel()
250253
go func() {
251254
ticker := time.NewTicker(p.opts.UpdateInterval)
252255
defer ticker.Stop()
@@ -256,6 +259,8 @@ func (p *Server) runJob(ctx context.Context, job *proto.AcquiredJob) {
256259
return
257260
case <-ctx.Done():
258261
return
262+
case <-complete.Done():
263+
return
259264
case <-p.shutdown:
260265
p.opts.Logger.Info(ctx, "attempting graceful cancelation")
261266
shutdownCancel()
@@ -816,6 +821,7 @@ func (p *Server) completeJob(job *proto.CompletedJob) {
816821
}
817822
if err != nil {
818823
p.opts.Logger.Warn(p.closeContext, "failed to complete job", slog.Error(err))
824+
p.failActiveJobf(err.Error())
819825
return
820826
}
821827
break

0 commit comments

Comments
 (0)