Fix Service.Restart double-restart and waitState busy loop#337
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Service.Restart behavior to avoid a second Stop+Start cycle after a successful native restart, and updates Service.waitState to avoid a tight busy loop by introducing a polling interval. Adds unit tests covering the service Start/Stop/Restart lifecycle methods.
Changes:
- Prevent
Service.Restartfrom falling through to Stop+Start whenRestartServicesucceeds (and wait for started state after native restart). - Add a fixed poll interval to
waitStateso state checks yield between probes. - Add tests for
Start,Stop, andRestart, including native-restart and cancellation/error cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| service.go | Fix restart fallthrough; add polling interval to waitState. |
| service_test.go | Add lifecycle tests and supporting mocks for Start/Stop/Restart. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dc60581 to
45bbe94
Compare
Service.Restart fell through to Stop+Start even when RestartService succeeded, causing the service to be restarted twice. Add return after waitState to stop the fallthrough. Service.waitState spun in a tight busy loop with no delay between ServiceIsRunning checks. Add a 500ms fixed poll interval so the loop yields between probes; context cancellation is still immediate via select. Also adds tests for Start, Stop, and Restart lifecycle methods, which previously had no coverage. Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
45bbe94 to
aeea217
Compare
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Service.Restart fell through to Stop+Start even when RestartService succeeded, causing the service to be restarted twice. Add return after waitState to stop the fallthrough.
Service.waitState spun in a tight busy loop with no delay between ServiceIsRunning checks. Add a 100..1000ms (backoff) poll interval so the loop yields between probes; context cancellation is still immediate via select.
Also adds tests for Start, Stop, and Restart lifecycle methods, which previously had no coverage.