opamp-go icon indicating copy to clipboard operation
opamp-go copied to clipboard

Fix race condition around supervisor's Commander

Open tpaschalis opened this issue 1 year ago • 4 comments

From what I'd see under normal circumstances (and also the example), starting up the supervisor which also launches the commander would happen in a separate goroutine than the one that inspects its state or calls Stop.

The current implementation has a race condition on the cmd *exec.Cmd field, using it both for figuring out whether the commander is running and also actually executing a new Agent process, which could potentially lead to a panic.

This PR fixes a small race condition around the supervisor's Commander by utilizing an existing running field and turning it into a atomic.Bool to store the commander's state.

Fixes #290

tpaschalis avatar Jul 01 '24 08:07 tpaschalis

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 77.06%. Comparing base (ed38d5f) to head (f135e3b). Report is 33 commits behind head on main.

Files with missing lines Patch % Lines
internal/noplogger.go 0.00% 4 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #291      +/-   ##
==========================================
+ Coverage   76.32%   77.06%   +0.74%     
==========================================
  Files          25       25              
  Lines        1681     1696      +15     
==========================================
+ Hits         1283     1307      +24     
+ Misses        291      286       -5     
+ Partials      107      103       -4     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 09 '24 16:07 codecov[bot]

@tpaschalis @srikanthccv is this still in progress?

tigrannajaryan avatar Aug 14 '24 14:08 tigrannajaryan

@tpaschalis @srikanthccv is this still in progress?

Srikanth had suggested using more explicit synchronization to avoid potentially leaving a dangling process; if the Shutdown method of the supervisor is called, then the isStoppingFlag will be set and the call to the commander's Start will abort before starting the new process.

I'm looking forward to feedback!

tpaschalis avatar Aug 14 '24 19:08 tpaschalis

@tpaschalis @srikanthccv I assume you are working on this PR. Please ping me when it is ready.

tigrannajaryan avatar Sep 06 '24 14:09 tigrannajaryan

@tpaschalis I am closing this. Please reopen if you plan to continue working on it.

tigrannajaryan avatar Feb 19 '25 19:02 tigrannajaryan