diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-05-24 17:51:52 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2023-05-25 11:45:51 +0200 |
| commit | f7e4c7256881bef31f5332d73c569a82cdd6cfbe (patch) | |
| tree | 0d4f00e28c4ea50a1456c4a143132dec6bf77644 /pkg | |
| parent | 453f56a20332a18969781dc145c8ae8da75468ea (diff) | |
pkg/report: restructure the shutdown process
Only use ctx.bootRequests to indicate that no further VMs are needed.
Do not return from Run() until we have fully stopped the VM creation
loop as there's a risk it might interfere with fuzzing.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/repro/repro.go | 21 | ||||
| -rw-r--r-- | pkg/repro/repro_test.go | 1 |
2 files changed, 14 insertions, 8 deletions
diff --git a/pkg/repro/repro.go b/pkg/repro/repro.go index b030d38bd..daebeed18 100644 --- a/pkg/repro/repro.go +++ b/pkg/repro/repro.go @@ -77,7 +77,14 @@ func Run(crashLog []byte, cfg *mgrconfig.Config, features *host.Features, report if err != nil { return nil, nil, err } - go ctx.createInstances(cfg, vmPool, vmIndexes) + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + ctx.createInstances(cfg, vmPool, vmIndexes) + }() + // Wait until all VMs are really released. + defer wg.Wait() return ctx.run() } @@ -135,12 +142,8 @@ func prepareCtx(crashLog []byte, cfg *mgrconfig.Config, features *host.Features, } func (ctx *context) run() (*Result, *Stats, error) { - defer func() { - close(ctx.bootRequests) - for inst := range ctx.instances { - inst.execProg.Close() - } - }() + // Indicate that we no longer need VMs. + defer close(ctx.bootRequests) res, err := ctx.repro() if err != nil { @@ -739,7 +742,11 @@ func (ctx *context) createInstances(cfg *mgrconfig.Config, vmPool *vm.Pool, vmIn }() } wg.Wait() + // Clean up. close(ctx.instances) + for inst := range ctx.instances { + inst.execProg.Close() + } } type Simplify func(opts *csource.Options) bool diff --git a/pkg/repro/repro_test.go b/pkg/repro/repro_test.go index 51c99eb75..ebe3809e0 100644 --- a/pkg/repro/repro_test.go +++ b/pkg/repro/repro_test.go @@ -119,7 +119,6 @@ func generateTestInstances(ctx *context, count int, execInterface execInterface) } }() wg.Wait() - close(ctx.instances) } type testExecInterface struct { |
