Fix race condition around supervisor's Commander
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
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.
@tpaschalis @srikanthccv is this still in progress?
@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 @srikanthccv I assume you are working on this PR. Please ping me when it is ready.
@tpaschalis I am closing this. Please reopen if you plan to continue working on it.