From 355865377102649df438e5d9dc7aa6d2a09bf7fc Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 2 Feb 2017 20:21:38 +0100 Subject: vm: properly detect when a program exits syz-fuzzer never exits (normally) so this does not affect syz-manager. But during reproduction we can run a short running program (no repeat mode) and currently VMs treat premature exit as an error. Properly detect when a program exits and let callers decide what to do with it. --- vm/gce/gce.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'vm/gce') diff --git a/vm/gce/gce.go b/vm/gce/gce.go index edce6c38e..364a44f29 100644 --- a/vm/gce/gce.go +++ b/vm/gce/gce.go @@ -214,13 +214,24 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin case <-inst.closed: signal(fmt.Errorf("instance closed")) case err := <-merger.Err: - // Check if the instance was terminated due to preemption or host maintenance. - time.Sleep(5 * time.Second) // just to avoid any GCE races - if !GCE.IsInstanceRunning(inst.name) { - Logf(1, "%v: ssh exited but instance is not running", inst.name) - err = vm.TimeoutErr + con.Process.Kill() + ssh.Process.Kill() + merger.Wait() + con.Wait() + if cmdErr := ssh.Wait(); cmdErr == nil { + // 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 { + // Check if the instance was terminated due to preemption or host maintenance. + time.Sleep(5 * time.Second) // just to avoid any GCE races + if !GCE.IsInstanceRunning(inst.name) { + Logf(1, "%v: ssh exited but instance is not running", inst.name) + err = vm.TimeoutErr + } } signal(err) + return } con.Process.Kill() ssh.Process.Kill() -- cgit mrf-deployment