Skip to content

Commit 84dd68a

Browse files
committed
Try #2 - don't create chan every acquirejob
1 parent 42ce721 commit 84dd68a

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

provisionerd/provisionerd.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ func New(clientDialer Dialer, opts *Options) io.Closer {
5050
}
5151
ctx, ctxCancel := context.WithCancel(context.Background())
5252
daemon := &provisionerDaemon{
53-
clientDialer: clientDialer,
54-
opts: opts,
55-
56-
closeContext: ctx,
57-
closeCancel: ctxCancel,
58-
closed: make(chan struct{}),
53+
clientDialer: clientDialer,
54+
opts: opts,
55+
acquiredJobDone: make(chan struct{}),
56+
closeContext: ctx,
57+
closeCancel: ctxCancel,
58+
closed: make(chan struct{}),
5959
}
6060
go daemon.connect(ctx)
6161
return daemon
@@ -185,8 +185,6 @@ func (p *provisionerDaemon) acquireJob(ctx context.Context) {
185185
p.acquiredJobCancelled.Store(false)
186186
p.acquiredJobRunning.Store(true)
187187

188-
p.acquiredJobDone = make(chan struct{})
189-
190188
p.opts.Logger.Info(context.Background(), "acquired job",
191189
slog.F("job_id", p.acquiredJob.JobId),
192190
slog.F("organization_name", p.acquiredJob.OrganizationName),
@@ -515,15 +513,6 @@ func (p *provisionerDaemon) closeWithError(err error) error {
515513
}
516514

517515
if p.isRunningJob() {
518-
// We also need the 'acquire job' mutex here,
519-
// so that a new `p.acquiredJobDone` channel isn't created
520-
// while we're waiting on the mutex.
521-
522-
// Note the mutex order - it's important that we always use the same order of acquisition
523-
// to avoid deadlocks
524-
p.acquiredJobMutex.Lock()
525-
defer p.acquiredJobMutex.Unlock()
526-
527516
errMsg := "provisioner daemon was shutdown gracefully"
528517
if err != nil {
529518
errMsg = err.Error()

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