diff options
| author | Taras Madan <tarasmadan@google.com> | 2025-05-15 15:01:02 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2025-05-19 09:39:47 +0000 |
| commit | 27f689959decd391b047c8034d481267d500549e (patch) | |
| tree | 79ce6364d592fd6841e25ec64ca645fc3c65cdcf /pkg/instance/execprog.go | |
| parent | 8f9cf946b3733d0b4ad3124bce155a4fc3849c3a (diff) | |
vm: func Run accepts context
It allows to use context as a single termination signal source.
Diffstat (limited to 'pkg/instance/execprog.go')
| -rw-r--r-- | pkg/instance/execprog.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/pkg/instance/execprog.go b/pkg/instance/execprog.go index 4fd656fc5..83461d07e 100644 --- a/pkg/instance/execprog.go +++ b/pkg/instance/execprog.go @@ -4,6 +4,7 @@ package instance import ( + "context" "fmt" "os" "time" @@ -123,7 +124,9 @@ func (inst *ExecProgInstance) runCommand(command string, duration time.Duration, if inst.BeforeContextLen != 0 { opts = append(opts, vm.OutputSize(inst.BeforeContextLen)) } - output, rep, err := inst.VMInstance.Run(duration, inst.reporter, command, opts...) + ctxTimeout, cancel := context.WithTimeout(context.Background(), duration) + defer cancel() + output, rep, err := inst.VMInstance.Run(ctxTimeout, inst.reporter, command, opts...) if err != nil { return nil, fmt.Errorf("failed to run command in VM: %w", err) } |
