Skip to content

Commit 44a5a46

Browse files
committed
Graceful shutdown
1 parent 6fc7a00 commit 44a5a46

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

claimutils/claim/claimer.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,25 @@ func (c *claimer) Start(ctx context.Context) error {
110110
}
111111

112112
go c.run(ctx)
113-
114113
<-ctx.Done()
115-
c.running.Store(false)
114+
116115
return nil
117116
}
118117

119118
func (c *claimer) run(ctx context.Context) {
119+
defer func() {
120+
c.running.Store(false)
121+
close(c.toClaim)
122+
close(c.toRelease)
123+
124+
for req := range c.toClaim {
125+
req.resultChan <- claimRes{err: ctx.Err()}
126+
}
127+
for req := range c.toRelease {
128+
req.resultChan <- ctx.Err()
129+
}
130+
}()
131+
120132
for {
121133
select {
122134
case <-ctx.Done():

claimutils/gpu/gpu_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var _ = Describe("GPU Claimer", func() {
3232
plugin := gpu.NewGPUClaimPlugin(log.FromContext(ctx), "test-plugin", nil, nil)
3333
Expect(plugin.Init()).Should(HaveOccurred())
3434

35-
By("init plugin without reader")
35+
By("init plugin reader")
3636
plugin = gpu.NewGPUClaimPlugin(log.FromContext(ctx), "test-plugin", &MockReader{}, nil)
3737
Expect(plugin.Init()).ShouldNot(HaveOccurred())
3838

0 commit comments

Comments
 (0)