From 73a168d010b3ba0a82f850b9fe73e6907539ff20 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 23 Apr 2025 12:32:03 +0200 Subject: vm/dispatcher: make pool.Run cancellable Make the pool.Run() function take a context.Context to be able to abort the callback passed to it or abort its scheduling if it's not yet running. Otherwise, if the callback is not yet started and the pool's Loop is aborted, we risk waiting for pool.Run() forever. It prevents the normal shutdown of repro.Run() and, consequently, the DiffFuzzer functionality. --- pkg/manager/diff.go | 6 +++++- pkg/repro/repro.go | 5 ++++- pkg/repro/strace.go | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'pkg') diff --git a/pkg/manager/diff.go b/pkg/manager/diff.go index 379fd246c..d7860cc9a 100644 --- a/pkg/manager/diff.go +++ b/pkg/manager/diff.go @@ -6,6 +6,7 @@ package manager import ( "context" "encoding/json" + "errors" "fmt" "math/rand" "net" @@ -583,7 +584,7 @@ func (rr *reproRunner) Run(ctx context.Context, r *repro.Result) { // The third time we leave it as is in case it was important. opts.Threaded = true } - pool.Run(func(ctx context.Context, inst *vm.Instance, updInfo dispatcher.UpdateInfo) { + runErr := pool.Run(ctx, func(ctx context.Context, inst *vm.Instance, updInfo dispatcher.UpdateInfo) { var ret *instance.ExecProgInstance ret, err = instance.SetupExecProg(inst, rr.kernel.cfg, rr.kernel.reporter, nil) if err != nil { @@ -595,6 +596,9 @@ func (rr *reproRunner) Run(ctx context.Context, r *repro.Result) { Opts: opts, }) }) + if errors.Is(runErr, context.Canceled) { + break + } crashed := result != nil && result.Report != nil log.Logf(1, "attempt #%d to run %q on base: crashed=%v", i, ret.origReport.Title, crashed) if crashed { diff --git a/pkg/repro/repro.go b/pkg/repro/repro.go index c196f71c7..1b3a70246 100644 --- a/pkg/repro/repro.go +++ b/pkg/repro/repro.go @@ -767,7 +767,7 @@ func (pw *poolWrapper) Run(ctx context.Context, params instance.ExecParams, var result *instance.RunResult var err error - pw.pool.Run(func(ctx context.Context, inst *vm.Instance, updInfo dispatcher.UpdateInfo) { + runErr := pw.pool.Run(ctx, func(ctx context.Context, inst *vm.Instance, updInfo dispatcher.UpdateInfo) { updInfo(func(info *dispatcher.Info) { typ := "syz" if params.CProg != nil { @@ -787,6 +787,9 @@ func (pw *poolWrapper) Run(ctx context.Context, params instance.ExecParams, result, err = ret.RunSyzProg(params) } }) + if runErr != nil { + return nil, runErr + } return result, err } diff --git a/pkg/repro/strace.go b/pkg/repro/strace.go index e101945cf..ceb31de93 100644 --- a/pkg/repro/strace.go +++ b/pkg/repro/strace.go @@ -31,7 +31,7 @@ func RunStrace(result *Result, cfg *mgrconfig.Config, reporter *report.Reporter, } var runRes *instance.RunResult var err error - pool.Run(func(ctx context.Context, inst *vm.Instance, updInfo dispatcher.UpdateInfo) { + runErr := pool.Run(context.Background(), func(ctx context.Context, inst *vm.Instance, updInfo dispatcher.UpdateInfo) { updInfo(func(info *dispatcher.Info) { info.Status = "running strace" }) @@ -58,7 +58,9 @@ func RunStrace(result *Result, cfg *mgrconfig.Config, reporter *report.Reporter, runRes, err = ret.RunSyzProg(params) } }) - if err != nil { + if runErr != nil { + return straceFailed(runErr) + } else if err != nil { return straceFailed(err) } return &StraceResult{ -- cgit mrf-deployment