Skip to content

Commit 5c72be1

Browse files
committed
fix: Remove race condition with acquiredJobDone channel
1 parent 03ed951 commit 5c72be1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

provisionerd/provisionerd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type provisionerDaemon struct {
9090
acquiredJobCancel context.CancelFunc
9191
acquiredJobCancelled atomic.Bool
9292
acquiredJobRunning atomic.Bool
93-
acquiredJobDone chan struct{}
93+
acquiredJobGroup sync.WaitGroup
9494
}
9595

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

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

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy