fix(engine): kill docker when timeout
This commit is contained in:
parent
f250034cd4
commit
4ea4a66b4b
|
|
@ -208,19 +208,6 @@ func (e *Docker) exec(box *config.Box, step *config.Step, req Request, dir strin
|
||||||
}
|
}
|
||||||
|
|
||||||
if err.Error() == "signal: killed" {
|
if err.Error() == "signal: killed" {
|
||||||
if step.Action == actionRun {
|
|
||||||
// we have to "docker kill" the container here, because the process
|
|
||||||
// inside the container is not related to the "docker run" process,
|
|
||||||
// and will hang forever after the "docker run" process is killed
|
|
||||||
go func() {
|
|
||||||
err = dockerKill(req.ID)
|
|
||||||
if err == nil {
|
|
||||||
logx.Debug("%s: docker kill ok", req.ID)
|
|
||||||
} else {
|
|
||||||
logx.Log("%s: docker kill failed: %v", req.ID, err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
// context timeout
|
// context timeout
|
||||||
err = ErrTimeout
|
err = ErrTimeout
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,19 @@ func (p *Program) RunStdin(stdin io.Reader, id, name string, arg ...string) (std
|
||||||
cmd.Cancel = func() error {
|
cmd.Cancel = func() error {
|
||||||
err := cmd.Process.Kill()
|
err := cmd.Process.Kill()
|
||||||
logx.Debug("%s: execution timeout, killed process=%d, err=%v", id, cmd.Process.Pid, err)
|
logx.Debug("%s: execution timeout, killed process=%d, err=%v", id, cmd.Process.Pid, err)
|
||||||
|
if arg[0] == actionRun {
|
||||||
|
// we have to "docker kill" the container here, because the process
|
||||||
|
// inside the container is not related to the "docker run" process,
|
||||||
|
// and will hang forever after the "docker run" process is killed
|
||||||
|
go func() {
|
||||||
|
err = dockerKill(id)
|
||||||
|
if err == nil {
|
||||||
|
logx.Debug("%s: docker kill ok", id)
|
||||||
|
} else {
|
||||||
|
logx.Log("%s: docker kill failed: %v", id, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user