@@ -421,12 +421,17 @@ func (api *API) updaterLoop() {
421
421
// advancing the clock.
422
422
ticker := api .clock .TickerFunc (api .ctx ,api .updateInterval ,func ()error {
423
423
done := make (chan error ,1 )
424
- defer close (done )
425
-
424
+ var sent bool
425
+ defer func () {
426
+ if ! sent {
427
+ close (done )
428
+ }
429
+ }()
426
430
select {
427
431
case <- api .ctx .Done ():
428
432
return api .ctx .Err ()
429
433
case api .updateTrigger <- done :
434
+ sent = true
430
435
err := <- done
431
436
if err != nil {
432
437
if errors .Is (err ,context .Canceled ) {
@@ -455,6 +460,7 @@ func (api *API) updaterLoop() {
455
460
// Note that although we pass api.ctx here, updateContainers
456
461
// has an internal timeout to prevent long blocking calls.
457
462
done <- api .updateContainers (api .ctx )
463
+ close (done )
458
464
}
459
465
}
460
466
}
@@ -798,12 +804,19 @@ func (api *API) RefreshContainers(ctx context.Context) (err error) {
798
804
}()
799
805
800
806
done := make (chan error ,1 )
807
+ var sent bool
808
+ defer func () {
809
+ if ! sent {
810
+ close (done )
811
+ }
812
+ }()
801
813
select {
802
814
case <- api .ctx .Done ():
803
815
return xerrors .Errorf ("API closed: %w" ,api .ctx .Err ())
804
816
case <- ctx .Done ():
805
817
return ctx .Err ()
806
818
case api .updateTrigger <- done :
819
+ sent = true
807
820
select {
808
821
case <- api .ctx .Done ():
809
822
return xerrors .Errorf ("API closed: %w" ,api .ctx .Err ())