Skip to content

Commit 1e03415

Browse files
committed
add more panic handler of new go routines
1 parent 4d9ed6a commit 1e03415

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

actionsdotnetactcompat/action_cache.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88
"errors"
99
"fmt"
1010
"io"
11+
"log"
1112
"net/http"
1213
"os"
1314
"path"
1415
"path/filepath"
16+
"runtime/debug"
1517
"strings"
1618

1719
"github.com/actions-oss/act-cli/pkg/common"
@@ -35,6 +37,11 @@ func (cache *ActionCacheBase) GetTarArchive(ctx context.Context, cacheDir, sha,
3537
pr, pw := io.Pipe()
3638
cleanIncludePrefix := path.Clean(includePrefix)
3739
go func() {
40+
defer func() {
41+
if r := recover(); r != nil {
42+
log.Printf("panic recovered: %v\n%s", r, debug.Stack())
43+
}
44+
}()
3845
defer func() { _ = pw.Close() }()
3946
writer := tar.NewWriter(pw)
4047
defer func() { _ = writer.Close() }()

actionsrunner/runner.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"io"
10+
"log"
1011
"net/http"
1112
"net/url"
1213
"path"
@@ -152,6 +153,11 @@ func (run *RunRunner) Run(runnerenv RunnerEnvironment, listenerctx, corectx cont
152153
for _, instance := range settings.Instances {
153154
//nolint:gosec
154155
go func(instance *runnerconfiguration.RunnerInstance) (exitcode int) {
156+
defer func() {
157+
if r := recover(); r != nil {
158+
log.Printf("panic recovered: %v\n%s", r, debug.Stack())
159+
}
160+
}()
155161
defer wg.Done()
156162
defer func() {
157163
// Without this the inner return 1 got lost and we would retry it
@@ -189,6 +195,11 @@ func (run *RunRunner) Run(runnerenv RunnerEnvironment, listenerctx, corectx cont
189195
Result: result,
190196
}
191197
go func() {
198+
defer func() {
199+
if r := recover(); r != nil {
200+
log.Printf("panic recovered: %v\n%s", r, debug.Stack())
201+
}
202+
}()
192203
for i := 0; ; i++ {
193204
if err := vssConnection.FinishJob(finish, jobrun.Plan); err != nil {
194205
runnerenv.Printf("Failed to finish previous stuck job with Status Failed: %v\n", err.Error())
@@ -450,6 +461,11 @@ func runJob(runnerenv RunnerEnvironment, joblock *sync.Mutex, vssConnection *pro
450461
session *protocol.AgentMessageConnection, message protocol.TaskAgentMessage, instance *runnerconfiguration.RunnerInstance,
451462
) {
452463
go func() {
464+
defer func() {
465+
if r := recover(); r != nil {
466+
log.Printf("panic recovered: %v\n%s", r, debug.Stack())
467+
}
468+
}()
453469
plogger := &PrefixConsoleLogger{
454470
Parent: runnerenv,
455471
Prefix: fmt.Sprintf("%v ( %v ):", instance.Agent.Name, instance.RegistrationURL),
@@ -539,6 +555,11 @@ func runJob(runnerenv RunnerEnvironment, joblock *sync.Mutex, vssConnection *pro
539555
}
540556
con := *vssConnection
541557
go func() {
558+
defer func() {
559+
if r := recover(); r != nil {
560+
log.Printf("panic recovered: %v\n%s", r, debug.Stack())
561+
}
562+
}()
542563
for {
543564
renewErr := renewJob(jobctx, runServiceURL, jobreq, &con, instance)
544565
if renewErr != nil {

main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"errors"
1010
"fmt"
1111
"io"
12+
"log"
1213
"os"
1314
"os/signal"
1415
"runtime"
16+
"runtime/debug"
1517
"strings"
1618
"syscall"
1719

@@ -120,6 +122,11 @@ func (run *RunRunner) Run() int {
120122
listenerctx, cancelListener := context.WithCancel(context.Background())
121123
defer cancelListener()
122124
go func() {
125+
defer func() {
126+
if r := recover(); r != nil {
127+
log.Printf("panic recovered: %v\n%s", r, debug.Stack())
128+
}
129+
}()
123130
sig := <-channel
124131
if sig == syscall.SIGTERM {
125132
fmt.Println("SIGTERM received, cancel any current job and wait for completion")
@@ -224,6 +231,11 @@ func (svc *RunRunnerSvc) Start(s service.Service) error {
224231
}
225232
svc.wait = make(chan error)
226233
go func() {
234+
defer func() {
235+
if r := recover(); r != nil {
236+
log.Printf("panic recovered: %v\n%s", r, debug.Stack())
237+
}
238+
}()
227239
defer cancelListener()
228240
defer cancel()
229241
defer close(svc.wait)
@@ -404,6 +416,11 @@ func main() {
404416
ccontext, cancelccontext := context.WithCancel(context.Background())
405417
defer cancelccontext()
406418
go func() {
419+
defer func() {
420+
if r := recover(); r != nil {
421+
log.Printf("panic recovered: %v\n%s", r, debug.Stack())
422+
}
423+
}()
407424
execcontext, cancelExec := context.WithCancel(context.Background())
408425
defer cancelExec()
409426
buf := make([]byte, bufferSize)
@@ -431,6 +448,11 @@ func main() {
431448
fmt.Printf("unmarshal job request: %v", err)
432449
}
433450
go func() {
451+
defer func() {
452+
if r := recover(); r != nil {
453+
log.Printf("panic recovered: %v\n%s", r, debug.Stack())
454+
}
455+
}()
434456
defer cancelExec()
435457
defer cancelccontext()
436458
wc := &actionsrunner.DefaultWorkerContext{

0 commit comments

Comments
 (0)