Skip to content

Commit a4e3c98

Browse files
committed
Instead of overriding process.returncode and utilizing that attribute to
determine if the process has timed out, utilize a special _timed_out attribute instead. This way we don't interfere with upstream logic which may base decisions based on the value of the process returncode value.
1 parent d1912e1 commit a4e3c98

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

st2common/st2common/util/green/shell.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def run_command(
154154
read_stderr_func, process.stderr, read_stderr_buffer
155155
)
156156

157+
# Special attribute we use to determine if the process timed out or not
158+
process._timed_out = False
159+
157160
def on_timeout_expired(timeout):
158161
global timed_out
159162

@@ -165,6 +168,8 @@ def on_timeout_expired(timeout):
165168
# Note: We explicitly set the returncode to indicate the timeout.
166169
LOG.debug("Command execution timeout reached.")
167170

171+
process._timed_out = True
172+
168173
if kill_func:
169174
LOG.debug("Calling kill_func.")
170175
kill_func(process=process)
@@ -173,9 +178,7 @@ def on_timeout_expired(timeout):
173178
process.kill()
174179

175180
process.wait()
176-
# NOTE: It's imporant to set returncode here as well, since call to process.kill() sets
177-
# it and overwrites it if we set it earlier.
178-
process.returncode = TIMEOUT_EXIT_CODE
181+
process._timed_out = True
179182

180183
if read_stdout_func and read_stderr_func:
181184
LOG.debug("Killing read_stdout_thread and read_stderr_thread")
@@ -202,7 +205,11 @@ def on_timeout_expired(timeout):
202205
stdout, stderr = process.communicate()
203206

204207
concurrency.cancel(timeout_thread)
205-
exit_code = process.returncode
208+
209+
if getattr(process, "_timed_out", False):
210+
exit_code = TIMEOUT_EXIT_CODE
211+
else:
212+
exit_code = process.returncode
206213

207214
if read_stdout_func and read_stderr_func:
208215
# Wait on those green threads to finish reading from stdout and stderr before continuing

0 commit comments

Comments
 (0)