fix subprocess handling when killed on timeout
@@ -165,10 +165,6 @@ def run_command(
# Note: We explicitly set the returncode to indicate the timeout.
LOG.debug("Command execution timeout reached.")
- # NOTE: It's important we set returncode twice - here and below to avoid race in this
- # function because "kill_func()" is async and "process.kill()" is not.
- process.returncode = TIMEOUT_EXIT_CODE
-
if kill_func:
LOG.debug("Calling kill_func.")
kill_func(process=process)
@@ -176,6 +172,7 @@ def run_command(
LOG.debug("Killing process.")
process.kill()
+ process.wait()
# NOTE: It's imporant to set returncode here as well, since call to process.kill() sets
# it and overwrites it if we set it earlier.
process.returncode = TIMEOUT_EXIT_CODE
