From 1ecfa2d8506efdae0483eedc0b425db8537b6e80 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Mon, 1 Jul 2024 18:54:32 +0200 Subject: 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. --- vm/vmimpl/vmimpl.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'vm/vmimpl/vmimpl.go') 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 -- cgit mrf-deployment