From e728b8594d6fca9c2a0207a116eb819135655317 Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Thu, 11 Jun 2020 16:17:24 -0400 Subject: [PATCH] fix race condition. (#538) --- src/Runner.Sdk/ProcessInvoker.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Runner.Sdk/ProcessInvoker.cs b/src/Runner.Sdk/ProcessInvoker.cs index 4ed4ce3b0..78a9f2dd2 100644 --- a/src/Runner.Sdk/ProcessInvoker.cs +++ b/src/Runner.Sdk/ProcessInvoker.cs @@ -346,14 +346,14 @@ namespace GitHub.Runner.Sdk // data buffers one last time before returning ProcessOutput(); - Trace.Info($"Finished process {_proc.Id} with exit code {_proc.ExitCode}, and elapsed time {_stopWatch.Elapsed}."); - } + if (cancellationToken.IsCancellationRequested) + { + // Ensure cancellation also finish on the cancellationToken.Register thread. + await cancellationFinished.Task; + Trace.Info($"Process Cancellation finished."); + } - if (cancellationToken.IsCancellationRequested) - { - // Ensure cancellation also finish on the cancellationToken.Register thread. - await cancellationFinished.Task; - Trace.Info($"Process Cancellation finished."); + Trace.Info($"Finished process {_proc.Id} with exit code {_proc.ExitCode}, and elapsed time {_stopWatch.Elapsed}."); } cancellationToken.ThrowIfCancellationRequested();