Skip to content

Race condition between Refresh and Start in ServiceHelper.StartServices #181

@Christophe-Rogiers

Description

@Christophe-Rogiers

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions