Skip to contentSkip to conversation

oeqa/ssh: Further improve process exit handling

PATCH New Richard Purdie 1 participant 1 message Jul 29, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 oeqa/ssh: Further improve process exit handling

It looks like there were further cases where orphaned processes may be left behind since the .kill() calls may be unsuccessful if the process terminated due to the terminate or through normal exit. In that situation .wait() wouldn't have been called.

Further tweak the exit code paths to ensure .wait() is called to update the returncode value before returning in all cases.

---
 meta/lib/oeqa/core/target/ssh.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
meta/lib/oeqa/core/target/ssh.py +3 -2
index 72ed1adbf89..f22836d390a 100644
@@ -265,7 +265,6 @@ def SSHCall(command, logger, timeout=None, **opts):
                 time.sleep(5)
                 try:
                     process.kill()
-                    process.wait()
                 except OSError:
                     logger.debug('OSError when killing process')
                     pass
@@ -274,6 +273,7 @@ def SSHCall(command, logger, timeout=None, **opts):
                             " running time: %d seconds." % (timeout, endtime))
                 logger.debug('Received data from SSH call:\n%s ' % lastline)
                 output += lastline
+                process.wait()
 
         else:
             output_raw = process.communicate()[0]
@@ -288,10 +288,10 @@ def SSHCall(command, logger, timeout=None, **opts):
             except TimeoutExpired:
                 try:
                     process.kill()
-                    process.wait()
                 except OSError:
                     logger.debug('OSError')
                     pass
+                process.wait()
 
     options = {
         "stdout": subprocess.PIPE,
@@ -318,6 +318,7 @@ def SSHCall(command, logger, timeout=None, **opts):
         # whilst running and ensure we don't leave a process behind.
         if process.poll() is None:
             process.kill()
+        if process.returncode == None:
             process.wait()
         logger.debug('Something went wrong, killing SSH process')
         raise
Signature · 1 line
2.39.2