From c2918417cbe2da7ee83deb316c3e8163f14b01a0 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 28 Sep 2016 18:05:28 +0200 Subject: vm: give preference to kernel oops over "lost connection" If lost connection races with a kernel oops (which probably caused the lost), give preference to the oops message (it should be more useful). --- vm/vm.go | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'vm') diff --git a/vm/vm.go b/vm/vm.go index ac60c8de0..f27fa200d 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -105,6 +105,24 @@ func MonitorExecution(outc <-chan []byte, errc <-chan error, local, needOutput b beforeContext = 256 << 10 afterContext = 128 << 10 ) + extractError := func(defaultError string) (string, []byte, []byte, bool, bool) { + // Give it some time to finish writing the error message. + waitForOutput() + if !report.ContainsCrash(output[matchPos:]) { + return defaultError, nil, output, true, false + } + desc, text, start, end := report.Parse(output[matchPos:]) + start = start + matchPos - beforeContext + if start < 0 { + start = 0 + } + end = end + matchPos + afterContext + if end > len(output) { + end = len(output) + } + return desc, text, output[start:end], true, false + } + lastExecuteTime := time.Now() ticker := time.NewTimer(3 * time.Minute) tickerFired := false @@ -123,8 +141,9 @@ func MonitorExecution(outc <-chan []byte, errc <-chan error, local, needOutput b case TimeoutErr: return err.Error(), nil, nil, false, true default: - waitForOutput() - return "lost connection to test machine", nil, output, true, false + // Note: connection lost can race with a kernel oops message. + // In such case we want to return the kernel oops. + return extractError("lost connection to test machine") } case out := <-outc: output = append(output, out...) @@ -135,18 +154,7 @@ func MonitorExecution(outc <-chan []byte, errc <-chan error, local, needOutput b lastExecuteTime = time.Now() } if report.ContainsCrash(output[matchPos:]) { - // Give it some time to finish writing the error message. - waitForOutput() - desc, text, start, end := report.Parse(output[matchPos:]) - start = start + matchPos - beforeContext - if start < 0 { - start = 0 - } - end = end + matchPos + afterContext - if end > len(output) { - end = len(output) - } - return desc, text, output[start:end], true, false + return extractError("") } if len(output) > 2*beforeContext { copy(output, output[len(output)-beforeContext:]) -- cgit mrf-deployment