From d1a1b0ca5ffc870174435e1a6878be98ee02dcd7 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 24 Jul 2024 17:44:20 +0200 Subject: pkg/runtest: fix a race during startup Run method usually runs in a separate goroutine concurrently with request consumer (Next calls), so at least executor needs to be initialized before Run. Otherwise we can get episodic nil derefs in Next method. --- pkg/runtest/run.go | 9 +++++++-- pkg/runtest/run_test.go | 1 + syz-manager/manager.go | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go index 501f92dd3..e0fefc31a 100644 --- a/pkg/runtest/run.go +++ b/pkg/runtest/run.go @@ -63,13 +63,18 @@ type Context struct { buildSem chan bool } +func (ctx *Context) Init() { + // Run usually runs in a separate goroutine concurrently with request consumer (Next calls), + // so at least executor needs to be initialized before Run. + ctx.executor = queue.DynamicOrder() + ctx.buildSem = make(chan bool, runtime.GOMAXPROCS(0)) +} + func (ctx *Context) log(msg string, args ...interface{}) { ctx.LogFunc(fmt.Sprintf(msg, args...)) } func (ctx *Context) Run(waitCtx context.Context) error { - ctx.buildSem = make(chan bool, runtime.GOMAXPROCS(0)) - ctx.executor = queue.DynamicOrder() ctx.generatePrograms() var ok, fail, broken, skip int for _, req := range ctx.requests { diff --git a/pkg/runtest/run_test.go b/pkg/runtest/run_test.go index 0861b7e2b..d0c3ca780 100644 --- a/pkg/runtest/run_test.go +++ b/pkg/runtest/run_test.go @@ -85,6 +85,7 @@ func test(t *testing.T, sysTarget *targets.Target) { Verbose: true, Debug: *flagDebug, } + ctx.Init() waitCtx := startRPCServer(t, target, executor, ctx, rpcParams{ manyProcs: true, machineChecked: func(features flatrpc.Feature) { diff --git a/syz-manager/manager.go b/syz-manager/manager.go index 367ade170..52d50109e 100644 --- a/syz-manager/manager.go +++ b/syz-manager/manager.go @@ -1389,6 +1389,7 @@ func (mgr *Manager) MachineChecked(features flatrpc.Feature, enabledSyscalls map Verbose: true, Debug: *flagDebug, } + ctx.Init() go func() { err := ctx.Run(context.Background()) if err != nil { -- cgit mrf-deployment