mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-07 15:50:28 +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
@@ -7,7 +7,9 @@ package common
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand/v2"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"gitea.com/gitea/runner/act/common/logging"
|
||||
)
|
||||
@@ -158,6 +160,28 @@ func (e Executor) IfBool(conditional bool) Executor {
|
||||
})
|
||||
}
|
||||
|
||||
// RetryBackoff is the wait between Retry's attempts, random between 1 and 10 seconds like GitHub's runner.
|
||||
var RetryBackoff = func() time.Duration { return time.Second + rand.N(9*time.Second) }
|
||||
|
||||
// Retry runs the executor up to attempts times until it succeeds.
|
||||
func (e Executor) Retry(attempts int) Executor {
|
||||
return func(ctx context.Context) error {
|
||||
for attempt := 1; ; attempt++ {
|
||||
err := e(ctx)
|
||||
if err == nil || attempt == attempts || ctx.Err() != nil {
|
||||
return err
|
||||
}
|
||||
backoff := RetryBackoff()
|
||||
Logger(ctx).Warnf("%v, retrying in %s", err, backoff.Round(time.Second))
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return err
|
||||
case <-time.After(backoff):
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finally adds an executor to run after other executor
|
||||
func (e Executor) Finally(finally Executor) Executor {
|
||||
return func(ctx context.Context) error {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -134,6 +135,31 @@ func TestExecutorConditionalsAndFinally(t *testing.T) {
|
||||
assert.Equal(t, []string{"if-true", "if-not", "if-bool", "main", "finally"}, calls)
|
||||
}
|
||||
|
||||
func TestExecutorRetryStopsOnSuccessOrAfterAllAttempts(t *testing.T) {
|
||||
backoff := RetryBackoff
|
||||
RetryBackoff = func() time.Duration { return 0 }
|
||||
t.Cleanup(func() { RetryBackoff = backoff })
|
||||
transient := errors.New("transient")
|
||||
for _, tc := range []struct {
|
||||
failures, calls int
|
||||
err error
|
||||
}{
|
||||
{failures: 2, calls: 3},
|
||||
{failures: 5, calls: 3, err: transient},
|
||||
} {
|
||||
var calls int
|
||||
err := Executor(func(context.Context) error {
|
||||
calls++
|
||||
if calls <= tc.failures {
|
||||
return transient
|
||||
}
|
||||
return nil
|
||||
}).Retry(3)(t.Context())
|
||||
require.Equal(t, tc.err, err)
|
||||
require.Equal(t, tc.calls, calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecutorFinallyReturnsFinallyErrorWithOriginal(t *testing.T) {
|
||||
finalErr := errors.New("cleanup failed")
|
||||
for _, mainErr := range []error{context.Canceled, nil} {
|
||||
|
||||
Reference in new issue
Block a user