From 866aaebac9ba6389df03af9dcecdda6b95f13ee4 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 29 Sep 2021 10:41:35 -0700 Subject: [PATCH 1/3] Retry installer Process.Start if ETXTBSY Fixes #53587 --- src/installer/tests/TestUtils/Command.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/installer/tests/TestUtils/Command.cs b/src/installer/tests/TestUtils/Command.cs index 3c3e5607dde90a..fcea947ba01715 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 @@ private static bool ShouldUseCmd(string executable) } 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,20 @@ public Command Start() ReportExecBegin(); - Process.Start(); + // Retry if we hit ETXTBSY due to Linux race + // https://github.com/dotnet/runtime/issues/58964 + for (int i = 0; i < 3; i++) + { + try + { + Process.Start(); + break; + } + catch (Win32Exception e) when (e.Message.Contains("Text file busy")) + { + Thread.Sleep(10); + } + } if (Process.StartInfo.RedirectStandardOutput) { From bdc375924b5b71371d2b13f7d3bafa16db9f8e7f Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 29 Sep 2021 10:45:04 -0700 Subject: [PATCH 2/3] Add comment --- src/installer/tests/TestUtils/Command.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/installer/tests/TestUtils/Command.cs b/src/installer/tests/TestUtils/Command.cs index fcea947ba01715..0348f9fb2b886e 100644 --- a/src/installer/tests/TestUtils/Command.cs +++ b/src/installer/tests/TestUtils/Command.cs @@ -208,6 +208,8 @@ public Command Start() } catch (Win32Exception e) when (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); } } From acc887934384eb4ad68d93b2e2c8d78a1d29fcd5 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 29 Sep 2021 12:52:16 -0700 Subject: [PATCH 3/3] Address PR comments --- src/installer/tests/TestUtils/Command.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/installer/tests/TestUtils/Command.cs b/src/installer/tests/TestUtils/Command.cs index 0348f9fb2b886e..096a53dd8302e3 100644 --- a/src/installer/tests/TestUtils/Command.cs +++ b/src/installer/tests/TestUtils/Command.cs @@ -199,14 +199,14 @@ public Command Start() // Retry if we hit ETXTBSY due to Linux race // https://github.com/dotnet/runtime/issues/58964 - for (int i = 0; i < 3; i++) + for (int i = 0; ; i++) { try { Process.Start(); break; } - catch (Win32Exception e) when (e.Message.Contains("Text file busy")) + 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