Skip to content

Commit 2c2b779

Browse files
authored
Merge pull request moby#3857 from tonistiigi/prune-lock-fix
control: fix possible deadlock on network error
2 parents 798c2c7 + 6cc7b2a commit 2c2b779

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)