Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita8725cd

Browse files
committed
Can't close a channel multiple times... switch to waitgroup
1 parent84dd68a commita8725cd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

‎provisionerd/provisionerd.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ 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-
acquiredJobDone:make(chanstruct{}),
56-
closeContext:ctx,
57-
closeCancel:ctxCancel,
58-
closed:make(chanstruct{}),
53+
clientDialer:clientDialer,
54+
opts:opts,
55+
closeContext:ctx,
56+
closeCancel:ctxCancel,
57+
closed:make(chanstruct{}),
5958
}
6059
godaemon.connect(ctx)
6160
returndaemon
@@ -90,7 +89,7 @@ type provisionerDaemon struct {
9089
acquiredJobCancel context.CancelFunc
9190
acquiredJobCancelled atomic.Bool
9291
acquiredJobRunning atomic.Bool
93-
acquiredJobDonechanstruct{}
92+
acquiredJobGroupsync.WaitGroup
9493
}
9594

9695
// Connect establishes a connection to coderd.
@@ -182,6 +181,7 @@ func (p *provisionerDaemon) acquireJob(ctx context.Context) {
182181
return
183182
}
184183
ctx,p.acquiredJobCancel=context.WithCancel(ctx)
184+
p.acquiredJobGroup.Add(1)
185185
p.acquiredJobCancelled.Store(false)
186186
p.acquiredJobRunning.Store(true)
187187

@@ -234,7 +234,7 @@ func (p *provisionerDaemon) runJob(ctx context.Context) {
234234
}
235235
p.opts.Logger.Debug(ctx,"cleaned up work directory")
236236
p.acquiredJobRunning.Store(false)
237-
close(p.acquiredJobDone)
237+
p.acquiredJobGroup.Done()
238238
}()
239239
// It's safe to cast this ProvisionerType. This data is coming directly from coderd.
240240
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)

[8]ページ先頭

©2009-2025 Movatter.jp