From b4a7bb09697e7d98c2ccef71cf69eb7c5bd4af97 Mon Sep 17 00:00:00 2001 From: Jun Sugimoto <47271927+sugymt@users.noreply.github.com> Date: Mon, 9 Oct 2023 13:20:04 +0900 Subject: [PATCH] Retries to lock Services database on Windows (#2880) --- .../NativeWindowsServiceHelper.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Runner.Listener/Configuration/NativeWindowsServiceHelper.cs b/src/Runner.Listener/Configuration/NativeWindowsServiceHelper.cs index 7ebc2a158..173e0bbe6 100644 --- a/src/Runner.Listener/Configuration/NativeWindowsServiceHelper.cs +++ b/src/Runner.Listener/Configuration/NativeWindowsServiceHelper.cs @@ -514,9 +514,25 @@ namespace GitHub.Runner.Listener.Configuration failureActions.Add(new FailureAction(RecoverAction.Restart, 60000)); // Lock the Service Database - svcLock = LockServiceDatabase(scmHndl); - if (svcLock.ToInt64() <= 0) + int svcLockRetries = 10; + int svcLockRetryTimeout = 5000; + while (true) { + svcLock = LockServiceDatabase(scmHndl); + if (svcLock.ToInt64() > 0) + { + break; + } + + _term.WriteLine("Retrying Lock Service Database..."); + + svcLockRetries--; + if (svcLockRetries > 0) + { + Thread.Sleep(svcLockRetryTimeout); + continue; + } + throw new Exception("Failed to Lock Service Database for Write"); }