Skip to content

Commit

Permalink
Retries to lock Services database on Windows (#2880)
Browse files Browse the repository at this point in the history
  • Loading branch information
sugymt authored Oct 9, 2023
1 parent f47384b commit b4a7bb0
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Runner.Listener/Configuration/NativeWindowsServiceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,25 @@ public void InstallService(string serviceName, string serviceDisplayName, string
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");
}

Expand Down

0 comments on commit b4a7bb0

Please sign in to comment.