From abe132d239d91c4ec33c9c27818f858bd13652dd Mon Sep 17 00:00:00 2001 From: Nedyalko Andreev Date: Mon, 8 Mar 2021 09:29:29 +0200 Subject: [PATCH] Fix metrics data race in the Engine test run finalization This should close https://github.com/loadimpact/k6/issues/1887 --- core/engine.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/engine.go b/core/engine.go index 1c527357281..51a31ff24aa 100644 --- a/core/engine.go +++ b/core/engine.go @@ -328,6 +328,15 @@ func (e *Engine) processMetrics(globalCtx context.Context, processMetricsAfterRu case <-ticker.C: processSamples() case <-processMetricsAfterRun: + getCachedMetrics: + for { + select { + case sc := <-e.Samples: + sampleContainers = append(sampleContainers, sc) + default: + break getCachedMetrics + } + } e.logger.Debug("Processing metrics and thresholds after the test run has ended...") processSamples() if !e.runtimeOptions.NoThresholds.Bool {