Close immediate channel after writing to it to close wait group in merge logic

This commit is contained in:
Philip Laine 2024-05-16 22:21:21 +02:00
parent 9794808333
commit aa98f85e9d
No known key found for this signature in database
GPG Key ID: F6D0B743CA3EFF33
2 changed files with 6 additions and 4 deletions

View File

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#483](https://github.com/XenitAB/spegel/pull/483) Update errcheck linter configuration and fix errors.
- [#487](https://github.com/XenitAB/spegel/pull/487) Move mirror metrics code to mirror handler.
- [#488](https://github.com/XenitAB/spegel/pull/488) Update existing registry errors and add more detail.
- [#490](https://github.com/XenitAB/spegel/pull/490) Close immediate channel after writing to it to close wait group in merge logic.
### Deprecated

View File

@ -20,16 +20,17 @@ func Track(ctx context.Context, ociClient oci.Client, router routing.Router, res
if err != nil {
return err
}
immediate := make(chan time.Time, 1)
immediate <- time.Now()
immediateCh := make(chan time.Time, 1)
immediateCh <- time.Now()
close(immediateCh)
expirationTicker := time.NewTicker(routing.KeyTTL - time.Minute)
defer expirationTicker.Stop()
ticker := channel.Merge(immediate, expirationTicker.C)
tickerCh := channel.Merge(immediateCh, expirationTicker.C)
for {
select {
case <-ctx.Done():
return nil
case <-ticker:
case <-tickerCh:
log.Info("running scheduled image state update")
if err := all(ctx, ociClient, router, resolveLatestTag); err != nil {
log.Error(err, "received errors when updating all images")