Skip to content

Commit bd06df0

Browse files
JoshuaWattEmantor
authored andcommitted
sshdriver: Cleanup after process exits
Cleanup of the temporary directory should not occur until after SSH has exited, as SSH will delete the control socket which can race with the shutil.rmtree() and result in strange errors like: tools/labgrid/venv/lib/python3.10/site-packages/labgrid/environment.py:65: in cleanup self.targets[target].cleanup() tools/labgrid/venv/lib/python3.10/site-packages/labgrid/target.py:555: in cleanup self.deactivate_all_drivers() tools/labgrid/venv/lib/python3.10/site-packages/labgrid/target.py:505: in deactivate_all_drivers self.deactivate(drv) tools/labgrid/venv/lib/python3.10/site-packages/labgrid/target.py:498: in deactivate client.on_deactivate() tools/labgrid/venv/lib/python3.10/site-packages/labgrid/driver/sshdriver.py:65: in on_deactivate self._cleanup_own_master() tools/labgrid/venv/lib/python3.10/site-packages/labgrid/driver/sshdriver.py:483: in _cleanup_own_master shutil.rmtree(self.tmpdir) /usr/lib/python3.10/shutil.py:724: in rmtree _rmtree_safe_fd(fd, path, onerror) /usr/lib/python3.10/shutil.py:680: in _rmtree_safe_fd onerror(os.unlink, fullname, sys.exc_info()) ... FileNotFoundError: [Errno 2] No such file or directory: 'control-172.16.6.0%enx5c857e32b0e4' Also ignore errors while running shutil.rmtree() since it a best effort cleanup Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com> (cherry picked from commit 937217b)
1 parent 5111f34 commit bd06df0

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

labgrid/driver/sshdriver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,11 @@ def _cleanup_own_master(self):
480480

481481
if res != 0:
482482
self.logger.info("Socket already closed")
483-
shutil.rmtree(self.tmpdir)
484483

485484
self.process.communicate()
486485

486+
shutil.rmtree(self.tmpdir, ignore_errors=True)
487+
487488
def _start_keepalive(self):
488489
"""Starts a keepalive connection via the own or external master."""
489490
args = ["ssh", *self.ssh_prefix, self.networkservice.address, "cat"]

0 commit comments

Comments
 (0)