Description
The code checks sc.Status then calls sc.Start(), but the status can change between the check and the call. If a service transitions from Stopped to StartPending between the check and the Start() call, an exception is thrown.
Location
src/Servy.Core/Helpers/ServiceHelper.cs, lines 76-82
Problematic code
if (sc.Status == ServiceControllerStatus.Stopped)
{
sc.Start();
}
Severity
Warning — Race condition can cause unhandled exception.
Suggested fix
Catch InvalidOperationException from Start() and handle gracefully, or retry with a fresh status check.
Description
The code checks
sc.Statusthen callssc.Start(), but the status can change between the check and the call. If a service transitions from Stopped to StartPending between the check and the Start() call, an exception is thrown.Location
src/Servy.Core/Helpers/ServiceHelper.cs, lines 76-82Problematic code
Severity
Warning — Race condition can cause unhandled exception.
Suggested fix
Catch
InvalidOperationExceptionfromStart()and handle gracefully, or retry with a fresh status check.