diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-07-01 18:54:32 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-07-02 16:22:10 +0000 |
| commit | 1ecfa2d8506efdae0483eedc0b425db8537b6e80 (patch) | |
| tree | 27b05fdd728cacbd56eab0eea5c5eca4fa65fda5 /vm/vmimpl | |
| parent | 07dedd50ee8834dbca4da7667e69e72b7d0565b9 (diff) | |
vm/gce: use vmimpl.Multiplex()
It will let us reduce code duplication and use the more appropriate
approach to the graceful Run() shutdown - by enforcing a delay between
stopping the command and stopping the collection of the console output.
Diffstat (limited to 'vm/vmimpl')
| -rw-r--r-- | vm/vmimpl/vmimpl.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/vm/vmimpl/vmimpl.go b/vm/vmimpl/vmimpl.go index a38ca0d8b..e29412d75 100644 --- a/vm/vmimpl/vmimpl.go +++ b/vm/vmimpl/vmimpl.go @@ -146,14 +146,24 @@ var ( Types = make(map[string]Type) ) +type CmdCloser struct { + *exec.Cmd +} + +func (cc CmdCloser) Close() error { + cc.Process.Kill() + return cc.Wait() +} + var WaitForOutputTimeout = 10 * time.Second type MultiplexConfig struct { - Console io.Closer - Stop <-chan bool - Close <-chan bool - Debug bool - Scale time.Duration + Console io.Closer + Stop <-chan bool + Close <-chan bool + Debug bool + Scale time.Duration + IgnoreError func(err error) bool } func Multiplex(cmd *exec.Cmd, merger *OutputMerger, timeout time.Duration, config MultiplexConfig) ( @@ -193,6 +203,8 @@ func Multiplex(cmd *exec.Cmd, merger *OutputMerger, timeout time.Duration, confi // If the command exited successfully, we got EOF error from merger. // But in this case no error has happened and the EOF is expected. err = nil + } else if config.IgnoreError != nil && config.IgnoreError(err) { + err = ErrTimeout } signal(err) return |
