1
0
Fork 0
mirror of https://github.com/Luzifer/elb-instance-status.git synced 2025-01-10 03:31:56 +00:00

Compare commits

..

2 commits

Author SHA1 Message Date
84df5e9f1a
prepare release v1.1.2 2024-04-20 14:05:25 +02:00
99391db514
Fix: Cleanup context after checks have run
in order not to leak context resources

Signed-off-by: Knut Ahlers <knut@ahlers.me>
2024-04-20 14:04:57 +02:00
2 changed files with 20 additions and 2 deletions

View file

@ -1,3 +1,7 @@
# 1.1.2 / 2024-04-20
* Fix: Cleanup context after checks have run
# 1.1.1 / 2024-04-19
* Update dependencies

View file

@ -8,6 +8,7 @@ import (
"net/url"
"os"
"os/exec"
"sync"
"time"
"github.com/sirupsen/logrus"
@ -143,9 +144,22 @@ func loadChecks() error {
}
func spawnChecks() {
ctx, _ := context.WithTimeout(context.Background(), cfg.CheckInterval-time.Second)
var wg sync.WaitGroup
ctx, cancel := context.WithTimeout(context.Background(), cfg.CheckInterval-time.Second)
wg.Add(len(checks))
go func() {
// Do not block the execution function but cleanup the context after
// all checks are done (or cancelled)
wg.Wait()
cancel()
}()
for id := range checks {
go executeAndRegisterCheck(ctx, id)
go func(ctx context.Context, id string) {
defer wg.Done()
executeAndRegisterCheck(ctx, id)
}(ctx, id)
}
}