mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-17 13:23:43 +00:00
fix: align process handling and fix Windows crashes (#1376)
The intermittent Windows test crashes came from step errors formatting a nil `rc.Run`. `fmt` recovers the nil dereference, but on CPUs with AMX the recovered fault overflows into the heap (https://github.com/golang/go/issues/81238). The errors now name the job, and the Windows test VM hides AMX and runs on UTC, so cached boots no longer jump back 8 hours mid-test. Windows commands now start suspended and resume once they are in their job objects, so no child escapes them. That drops the process scan reading other processes' memory and the last `unsafe` code, which `depguard` now denies. Step processes outlive a crashed runner, and commands are no longer looked up in the runner's working directory, both as with GitHub's runner. Like GitHub's runner, host jobs on Linux and macOS now end the processes carrying the job's `RUNNER_TRACKING_ID`, and image pulls and Dockerfile action builds are retried. Reviewed-on: https://gitea.com/gitea/runner/pulls/1376 Reviewed-by: bircni <[email protected]> Co-authored-by: silverwind <[email protected]>
This commit is contained in:
1 parent
142d9f8c88
commit
dcba546cb3
32 files changed
+374
-593
No files matched your search
@@ -36,9 +36,9 @@ type TreeKill struct {
|
||||
KeepLeftovers bool
|
||||
}
|
||||
|
||||
// NewTreeKill sets cmd.Cancel and cmd.WaitDelay. Call it before cmd.Start, then
|
||||
// call Capture once after a successful Start.
|
||||
// NewTreeKill sets cmd.Cancel, cmd.WaitDelay and CREATE_SUSPENDED. Call it after setting cmd.SysProcAttr, and Capture once after a successful Start.
|
||||
func NewTreeKill(cmd *exec.Cmd) *TreeKill {
|
||||
startSuspended(cmd)
|
||||
t := &TreeKill{}
|
||||
cmd.Cancel = func() error {
|
||||
if k := t.killer.Load(); k != nil {
|
||||
@@ -63,14 +63,17 @@ func NewTreeKill(cmd *exec.Cmd) *TreeKill {
|
||||
// Call it once after cmd.Start. On failure the command falls back to the default
|
||||
// single-process kill and the returned error is for logging only; WaitDelay
|
||||
// still bounds the wait. The returned Killer should be closed when the command
|
||||
// finishes (Close is nil-safe).
|
||||
// finishes (Close is nil-safe). It also resumes p.
|
||||
func (t *TreeKill) Capture(p *os.Process) (*Killer, error) {
|
||||
k, err := NewKiller(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err == nil {
|
||||
t.killer.Store(k)
|
||||
}
|
||||
t.killer.Store(k)
|
||||
return k, nil
|
||||
if resumeErr := resume(p); resumeErr != nil {
|
||||
_ = p.Kill()
|
||||
return nil, errors.Join(err, k.Close(), resumeErr)
|
||||
}
|
||||
return k, err
|
||||
}
|
||||
|
||||
// Wait is cmd.Wait, but like GitHub's runner a leftover holding a successful command's output does not fail it.
|
||||
|
||||
Reference in new issue
Block a user