1
0
Fork 0
mirror of https://github.com/Luzifer/waitfor.git synced 2024-12-20 18:31:20 +00:00

Fix: Ensure cancel is called

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-10-18 23:26:58 +02:00
parent dbb3278c4f
commit da31447657
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -74,6 +74,7 @@ func executeCommand(cmdStr []string) error {
)
if cfg.CommandTimeout > 0 {
ctx, cancel = context.WithTimeout(context.Background(), cfg.CommandTimeout)
defer cancel()
}
go func() {
@ -86,7 +87,6 @@ func executeCommand(cmdStr []string) error {
cmd.Process.Kill()
return errors.New("Command execution timed out")
case err := <-c:
cancel()
return err
}
}