Bug 2123 fixed 02/12402/2
authorPedro Escaleira <escaleira@av.it.pt>
Sat, 23 Jul 2022 22:34:42 +0000 (23:34 +0100)
committercalvinosanc1 <guillermo.calvino@canonical.com>
Wed, 28 Sep 2022 14:01:14 +0000 (16:01 +0200)
 - Killing the subprocesses launched in both
   _local_async_exec and _local_async_exec_pipe methods if cancelled

Change-Id: I89d15fa20246407f8e5942960151b1265ec2d298
Signed-off-by: Pedro Escaleira <escaleira@av.it.pt>
n2vc/k8s_helm_base_conn.py

index c20b55d..afd9d5e 100644 (file)
@@ -1547,6 +1547,9 @@ class K8sHelmBaseConnector(K8sConnector):
             return output, return_code
 
         except asyncio.CancelledError:
+            # first, kill the process if it is still running
+            if process.returncode is None:
+                process.kill()
             raise
         except K8sException:
             raise
@@ -1586,7 +1589,7 @@ class K8sHelmBaseConnector(K8sConnector):
         try:
             async with self.cmd_lock:
                 read, write = os.pipe()
-                await asyncio.create_subprocess_exec(
+                process_1 = await asyncio.create_subprocess_exec(
                     *command1, stdout=write, env=environ
                 )
                 os.close(write)
@@ -1622,6 +1625,10 @@ class K8sHelmBaseConnector(K8sConnector):
 
             return output, return_code
         except asyncio.CancelledError:
+            # first, kill the processes if they are still running
+            for process in (process_1, process_2):
+                if process.returncode is None:
+                    process.kill()
             raise
         except K8sException:
             raise