1
0
Fork 0
mirror of https://github.com/Luzifer/elb-instance-status.git synced 2024-12-22 19:01:19 +00:00

Fix: Cleanup context after checks have run

in order not to leak context resources

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-04-20 14:04:57 +02:00
parent 879faa0a36
commit 99391db514
Signed by: luzifer
SSH key fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E

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)
}
}