File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -422,12 +422,17 @@ func (api *API) updaterLoop() {
422
422
// advancing the clock.
423
423
ticker := api .clock .TickerFunc (api .ctx , api .updateInterval , func () error {
424
424
done := make (chan error , 1 )
425
- defer close (done )
426
-
425
+ var sent bool
426
+ defer func () {
427
+ if ! sent {
428
+ close (done )
429
+ }
430
+ }()
427
431
select {
428
432
case <- api .ctx .Done ():
429
433
return api .ctx .Err ()
430
434
case api .updateTrigger <- done :
435
+ sent = true
431
436
err := <- done
432
437
if err != nil {
433
438
if errors .Is (err , context .Canceled ) {
@@ -456,6 +461,7 @@ func (api *API) updaterLoop() {
456
461
// Note that although we pass api.ctx here, updateContainers
457
462
// has an internal timeout to prevent long blocking calls.
458
463
done <- api .updateContainers (api .ctx )
464
+ close (done )
459
465
}
460
466
}
461
467
}
@@ -800,12 +806,19 @@ func (api *API) RefreshContainers(ctx context.Context) (err error) {
800
806
}()
801
807
802
808
done := make (chan error , 1 )
809
+ var sent bool
810
+ defer func () {
811
+ if ! sent {
812
+ close (done )
813
+ }
814
+ }()
803
815
select {
804
816
case <- api .ctx .Done ():
805
817
return xerrors .Errorf ("API closed: %w" , api .ctx .Err ())
806
818
case <- ctx .Done ():
807
819
return ctx .Err ()
808
820
case api .updateTrigger <- done :
821
+ sent = true
809
822
select {
810
823
case <- api .ctx .Done ():
811
824
return xerrors .Errorf ("API closed: %w" , api .ctx .Err ())
You can’t perform that action at this time.
0 commit comments