Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9742259

Browse files
committed
Fix race in shutdown
1 parent c21e20e commit 9742259

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

provisionerd/provisionerd.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,18 @@ func (p *Server) runJob(ctx context.Context, job *proto.AcquiredJob) {
230230
go func() {
231231
ticker := time.NewTicker(p.opts.UpdateInterval)
232232
defer ticker.Stop()
233-
select {
234-
case <-p.closed:
235-
return
236-
case <-ctx.Done():
237-
return
238-
case <-p.shutdown:
239-
p.opts.Logger.Info(ctx, "attempting graceful cancelation")
240-
shutdownCancel()
241-
return
242-
case <-ticker.C:
233+
for {
234+
select {
235+
case <-p.closed:
236+
return
237+
case <-ctx.Done():
238+
return
239+
case <-p.shutdown:
240+
p.opts.Logger.Info(ctx, "attempting graceful cancelation")
241+
shutdownCancel()
242+
return
243+
case <-ticker.C:
244+
}
243245
resp, err := p.client.UpdateJob(ctx, &proto.UpdateJobRequest{
244246
JobId: job.JobId,
245247
})
@@ -248,7 +250,7 @@ func (p *Server) runJob(ctx context.Context, job *proto.AcquiredJob) {
248250
return
249251
}
250252
if !resp.Canceled {
251-
return
253+
continue
252254
}
253255
p.opts.Logger.Info(ctx, "attempting graceful cancelation")
254256
shutdownCancel()

0 commit comments

Comments
 (0)