Skip to content

fix: remove race condition w/ acquiredJobDone chan #148

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions provisionerd/provisionerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type provisionerDaemon struct {
acquiredJobCancel context.CancelFunc
acquiredJobCancelled atomic.Bool
acquiredJobRunning atomic.Bool
acquiredJobDone chan struct{}
acquiredJobGroup sync.WaitGroup
}

// Connect establishes a connection to coderd.
Expand Down Expand Up @@ -184,7 +184,7 @@ func (p *provisionerDaemon) acquireJob(ctx context.Context) {
ctx, p.acquiredJobCancel = context.WithCancel(ctx)
p.acquiredJobCancelled.Store(false)
p.acquiredJobRunning.Store(true)
p.acquiredJobDone = make(chan struct{})
p.acquiredJobGroup.Add(1)

p.opts.Logger.Info(context.Background(), "acquired job",
slog.F("organization_name", p.acquiredJob.OrganizationName),
Expand Down Expand Up @@ -235,7 +235,7 @@ func (p *provisionerDaemon) runJob(ctx context.Context) {
p.acquiredJobMutex.Lock()
defer p.acquiredJobMutex.Unlock()
p.acquiredJobRunning.Store(false)
close(p.acquiredJobDone)
p.acquiredJobGroup.Done()
}()
// It's safe to cast this ProvisionerType. This data is coming directly from coderd.
provisioner, hasProvisioner := p.opts.Provisioners[p.acquiredJob.Provisioner]
Expand Down Expand Up @@ -520,7 +520,7 @@ func (p *provisionerDaemon) closeWithError(err error) error {
if !p.acquiredJobCancelled.Load() {
p.cancelActiveJob(errMsg)
}
<-p.acquiredJobDone
p.acquiredJobGroup.Wait()
}

p.opts.Logger.Debug(context.Background(), "closing server with error", slog.Error(err))
Expand Down