Skip to content

Commit 6cc7b2a

Browse files
committed
control: fix possible deadlock on network error
When error appears on sending to network, channel still needs to be read empty to ensure that the other side does not get blocked on sending to the channel. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 6d4901c commit 6cc7b2a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

control/control.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (c *Controller) Prune(req *controlapi.PruneRequest, stream controlapi.Contr
168168
imageutil.CancelCacheLeases()
169169
}
170170

171-
ch := make(chan client.UsageInfo)
171+
ch := make(chan client.UsageInfo, 32)
172172

173173
eg, ctx := errgroup.WithContext(stream.Context())
174174
workers, err := c.opt.WorkerController.List()
@@ -210,6 +210,11 @@ func (c *Controller) Prune(req *controlapi.PruneRequest, stream controlapi.Contr
210210
})
211211

212212
eg2.Go(func() error {
213+
defer func() {
214+
// drain channel on error
215+
for range ch {
216+
}
217+
}()
213218
for r := range ch {
214219
didPrune = true
215220
if err := stream.Send(&controlapi.UsageRecord{
@@ -450,6 +455,11 @@ func (c *Controller) Status(req *controlapi.StatusRequest, stream controlapi.Con
450455
})
451456

452457
eg.Go(func() error {
458+
defer func() {
459+
// drain channel on error
460+
for range ch {
461+
}
462+
}()
453463
for {
454464
ss, ok := <-ch
455465
if !ok {

0 commit comments

Comments
 (0)