mirror of
https://github.com/Luzifer/elb-instance-status.git
synced 2024-12-22 10:51:19 +00:00
Fix memory leak as of unclosed loggers
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
84df5e9f1a
commit
95473e70f3
1 changed files with 12 additions and 2 deletions
14
checks.go
14
checks.go
|
@ -39,12 +39,22 @@ func executeAndRegisterCheck(ctx context.Context, checkID string) {
|
||||||
var (
|
var (
|
||||||
check = checks[checkID]
|
check = checks[checkID]
|
||||||
logger = logrus.WithField("check_id", checkID)
|
logger = logrus.WithField("check_id", checkID)
|
||||||
|
stderr = logger.WithField("stream", "STDERR").Writer()
|
||||||
|
stdout = logger.WithField("stream", "STDOUT").Writer()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
for _, c := range []io.Closer{stderr, stdout} {
|
||||||
|
if err := c.Close(); err != nil {
|
||||||
|
logrus.WithError(err).Error("closing check log-writer (leaked mem)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
cmd := exec.Command("/bin/bash", "-e", "-o", "pipefail", "-c", check.Command) //#nosec G204 // Intended to run an user-defined command
|
cmd := exec.Command("/bin/bash", "-e", "-o", "pipefail", "-c", check.Command) //#nosec G204 // Intended to run an user-defined command
|
||||||
cmd.Stderr = logger.WithField("stream", "STDERR").Writer()
|
cmd.Stderr = stderr
|
||||||
if cfg.Verbose {
|
if cfg.Verbose {
|
||||||
cmd.Stdout = logger.WithField("stream", "STDOUT").Writer()
|
cmd.Stdout = stdout
|
||||||
}
|
}
|
||||||
err := cmd.Start()
|
err := cmd.Start()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue