mirror of
https://github.com/Luzifer/waitfor.git
synced 2024-12-21 02:41:20 +00:00
Fix: Ensure cancel is called
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
dbb3278c4f
commit
da31447657
1 changed files with 1 additions and 1 deletions
2
main.go
2
main.go
|
@ -74,6 +74,7 @@ func executeCommand(cmdStr []string) error {
|
||||||
)
|
)
|
||||||
if cfg.CommandTimeout > 0 {
|
if cfg.CommandTimeout > 0 {
|
||||||
ctx, cancel = context.WithTimeout(context.Background(), cfg.CommandTimeout)
|
ctx, cancel = context.WithTimeout(context.Background(), cfg.CommandTimeout)
|
||||||
|
defer cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -86,7 +87,6 @@ func executeCommand(cmdStr []string) error {
|
||||||
cmd.Process.Kill()
|
cmd.Process.Kill()
|
||||||
return errors.New("Command execution timed out")
|
return errors.New("Command execution timed out")
|
||||||
case err := <-c:
|
case err := <-c:
|
||||||
cancel()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue