From 8dd058a5da722e0235bbdc3d205e86dd269d5bee Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 29 Sep 2021 16:22:37 -0700 Subject: [PATCH] Retry installer Process.Start if ETXTBSY (#59765) Caused by #58964 Fixes #53587 --- src/installer/tests/TestUtils/Command.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/installer/tests/TestUtils/Command.cs b/src/installer/tests/TestUtils/Command.cs index 3c3e560..096a53d 100644 --- a/src/installer/tests/TestUtils/Command.cs +++ b/src/installer/tests/TestUtils/Command.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; @@ -120,7 +121,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework } else { - // Search the path to see if we can find it + // Search the path to see if we can find it foreach (var path in System.Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator)) { var candidate = Path.Combine(path, executable + ".exe"); @@ -196,7 +197,22 @@ namespace Microsoft.DotNet.Cli.Build.Framework ReportExecBegin(); - Process.Start(); + // Retry if we hit ETXTBSY due to Linux race + // https://github.com/dotnet/runtime/issues/58964 + for (int i = 0; ; i++) + { + try + { + Process.Start(); + break; + } + catch (Win32Exception e) when (i < 3 && e.Message.Contains("Text file busy")) + { + // 10 ms is short, but the race we're trying to avoid is in-between + // "fork" and "exec", so it should be fast + Thread.Sleep(10); + } + } if (Process.StartInfo.RedirectStandardOutput) { -- 2.7.4