mirror of
https://github.com/Luzifer/elb-instance-status.git
synced 2024-11-08 14:00:09 +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:
parent
879faa0a36
commit
99391db514
1 changed files with 16 additions and 2 deletions
18
checks.go
18
checks.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -143,9 +144,22 @@ func loadChecks() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func spawnChecks() {
|
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 {
|
for id := range checks {
|
||||||
go executeAndRegisterCheck(ctx, id)
|
go func(ctx context.Context, id string) {
|
||||||
|
defer wg.Done()
|
||||||
|
executeAndRegisterCheck(ctx, id)
|
||||||
|
}(ctx, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue