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

Skip to content

chore: Improve CI builds by improving caching and decomposing steps #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 22, 2022
Prev Previous commit
Fix race in shutdown
  • Loading branch information
kylecarbs committed Mar 22, 2022
commit 92b488e81457ac0bb5250fefc0bae4698311628e
26 changes: 14 additions & 12 deletions provisionerd/provisionerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,18 @@ func (p *Server) runJob(ctx context.Context, job *proto.AcquiredJob) {
go func() {
ticker := time.NewTicker(p.opts.UpdateInterval)
defer ticker.Stop()
select {
case <-p.closed:
return
case <-ctx.Done():
return
case <-p.shutdown:
p.opts.Logger.Info(ctx, "attempting graceful cancelation")
shutdownCancel()
return
case <-ticker.C:
for {
select {
case <-p.closed:
return
case <-ctx.Done():
return
case <-p.shutdown:
p.opts.Logger.Info(ctx, "attempting graceful cancelation")
shutdownCancel()
return
case <-ticker.C:
}
resp, err := p.client.UpdateJob(ctx, &proto.UpdateJobRequest{
JobId: job.JobId,
})
Expand All @@ -248,18 +250,18 @@ func (p *Server) runJob(ctx context.Context, job *proto.AcquiredJob) {
return
}
if !resp.Canceled {
return
continue
}
p.opts.Logger.Info(ctx, "attempting graceful cancelation")
shutdownCancel()
// Hard-cancel the job after a minute of pending cancelation.
timer := time.NewTimer(p.opts.ForceCancelInterval)
defer timer.Stop()
select {
case <-timer.C:
p.failActiveJobf("cancelation timed out")
return
case <-ctx.Done():
timer.Stop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we only want to stop the timer on a context cancel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timer will automatically stop if it completes, since it's not a ticker!

return
}
}
Expand Down