OK-5110 make stop synchronous#59
Merged
Merged
Conversation
spikeburton
approved these changes
Apr 29, 2026
| deadline = time.monotonic() + STOP_WAIT_TIMEOUT | ||
| while time.monotonic() < deadline: | ||
| try: | ||
| # Sending signal 0 checks if the process exists without |
Contributor
There was a problem hiding this comment.
nit - I do not think this comment is needed. This is a common way to query if the process is running, in fact we use it in the run-avd script itself here
But it doesn't add too much noise, so I am fine to leave it, upto you
Contributor
Author
There was a problem hiding this comment.
Removed that comment.
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.
Summary
Make
avdmodule'sstop()action synchronous: wait for the run-avd process to actually exit before returning, instead of fire-and-forget on SIGTERM.Problem
avd.py'sstop()previously sent SIGTERM and returned immediately:Since
/opt/orka/bin/run-avdis a bash script that manages child processes (the emulator and socat relay), it can take a few seconds to handle SIGTERM and exit cleanly. Callers that immediately query AVD state (viagather_avd_factsorpgrep) see the AVD as still "running" — even though the stop call succeeded.This caused validation steps in our CI workflow to flake, and would surface as a confusing "AVD is running" state in any subsequent task that depends on a stop having taken effect.
Fix
After sending SIGTERM, poll the process with
kill(pid, 0)until it exits or the 30s timeout expires. If the process doesn't exit in time, fail the task explicitly so callers know the stop didn't take effect.Test plan
avd.yml -e desired_state=stoppedagainst a running AVD — confirm task only returns after the process is actually gone (pgrep -f run-avd | grep <name>returns nothing immediately after)avd.yml -e desired_state=stoppedagainst a stuck process (e.g. one trapping SIGTERM) — confirm the task fails with a clear timeout message rather than reporting success