diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2025-04-15 15:15:13 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-04-15 15:55:41 +0000 |
| commit | 2197b25c207a81e893d3ac531c1bf215d8ee442d (patch) | |
| tree | 4ed23be09178bf47e37fa7942445a2106d81b3ea | |
| parent | bb6cd4d997e87dfb38beef17406efd58174424b3 (diff) | |
pkg/manager: propagate context to the bug reproduction
If the context is cancelled, we need to make sure that the reproduction
process is aborted as well.
| -rw-r--r-- | pkg/manager/diff.go | 4 | ||||
| -rw-r--r-- | pkg/manager/repro.go | 8 | ||||
| -rw-r--r-- | pkg/manager/repro_test.go | 15 | ||||
| -rw-r--r-- | syz-manager/manager.go | 4 |
4 files changed, 20 insertions, 11 deletions
diff --git a/pkg/manager/diff.go b/pkg/manager/diff.go index 781ac0152..d0cb33aa3 100644 --- a/pkg/manager/diff.go +++ b/pkg/manager/diff.go @@ -272,12 +272,12 @@ func (dc *diffContext) NeedRepro(crash *Crash) bool { return true } -func (dc *diffContext) RunRepro(crash *Crash) *ReproResult { +func (dc *diffContext) RunRepro(ctx context.Context, crash *Crash) *ReproResult { dc.mu.Lock() dc.reproAttempts[crash.Title]++ dc.mu.Unlock() - res, stats, err := repro.Run(context.Background(), crash.Output, repro.Environment{ + res, stats, err := repro.Run(ctx, crash.Output, repro.Environment{ Config: dc.new.cfg, Features: dc.new.features, Reporter: dc.new.reporter, diff --git a/pkg/manager/repro.go b/pkg/manager/repro.go index c7afe9845..1531f3d8d 100644 --- a/pkg/manager/repro.go +++ b/pkg/manager/repro.go @@ -46,7 +46,7 @@ func (c *Crash) FullTitle() string { } type ReproManagerView interface { - RunRepro(crash *Crash) *ReproResult + RunRepro(ctx context.Context, crash *Crash) *ReproResult NeedRepro(crash *Crash) bool ResizeReproPool(size int) } @@ -222,7 +222,7 @@ func (r *ReproLoop) Loop(ctx context.Context) { go func() { defer wg.Done() - r.handle(crash) + r.handle(ctx, crash) r.mu.Lock() delete(r.reproducing, title) @@ -244,10 +244,10 @@ func (r *ReproLoop) calculateReproVMs(repros int) int { return (repros*4 + 2) / 3 } -func (r *ReproLoop) handle(crash *Crash) { +func (r *ReproLoop) handle(ctx context.Context, crash *Crash) { log.Logf(0, "start reproducing '%v'", crash.FullTitle()) - res := r.mgr.RunRepro(crash) + res := r.mgr.RunRepro(ctx, crash) crepro := false title := "" diff --git a/pkg/manager/repro_test.go b/pkg/manager/repro_test.go index f0b95d97c..def436e99 100644 --- a/pkg/manager/repro_test.go +++ b/pkg/manager/repro_test.go @@ -147,10 +147,19 @@ func (m *reproMgrMock) onVMShutdown(t *testing.T, reproLoop *ReproLoop) { t.Fatal("reserved VMs must have dropped to 0") } -func (m *reproMgrMock) RunRepro(crash *Crash) *ReproResult { +func (m *reproMgrMock) RunRepro(ctx context.Context, crash *Crash) *ReproResult { retCh := make(chan *ReproResult) - m.run <- runCallback{crash: crash, ret: retCh} - ret := <-retCh + select { + case m.run <- runCallback{crash: crash, ret: retCh}: + case <-ctx.Done(): + return &ReproResult{} + } + var ret *ReproResult + select { + case ret = <-retCh: + case <-ctx.Done(): + return &ReproResult{} + } close(retCh) return ret } diff --git a/syz-manager/manager.go b/syz-manager/manager.go index f76d0ad8d..a8189e62f 100644 --- a/syz-manager/manager.go +++ b/syz-manager/manager.go @@ -505,8 +505,8 @@ func reportReproError(err error) { log.Errorf("repro failed: %v", err) } -func (mgr *Manager) RunRepro(crash *manager.Crash) *manager.ReproResult { - res, stats, err := repro.Run(context.Background(), crash.Output, repro.Environment{ +func (mgr *Manager) RunRepro(ctx context.Context, crash *manager.Crash) *manager.ReproResult { + res, stats, err := repro.Run(ctx, crash.Output, repro.Environment{ Config: mgr.cfg, Features: mgr.enabledFeatures, Reporter: mgr.reporter, |
