From b884a180c8253ba8edd5679e1fa4aaae6a6e0537 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 29 Nov 2022 19:22:27 +0000 Subject: [PATCH] Add exit handling --- sshim_patch.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/sshim_patch.py b/sshim_patch.py index dc1c3f8..286f4d8 100644 --- a/sshim_patch.py +++ b/sshim_patch.py @@ -80,32 +80,41 @@ class Runner(threading.Thread): if self.shell_channel in r: x = self.shell_channel.recv(1024) if len(x) == 0: - break + self.shell_channel = None client_shell_channel.send(x) if client_shell_channel in r: x = client_shell_channel.recv(1024) if len(x) == 0: - break + self.shell_channel = None self.shell_channel.send(x) - if self.sftp_channel is not None: # TODO: move this to function + if self.sftp_channel is not None: # TODO: move this to function r, w, e = select.select([client_sftp_channel, self.sftp_channel], [], []) if self.sftp_channel in r: x = self.sftp_channel.recv(1024) if len(x) == 0: - break + self.sftp_channel = None client_sftp_channel.send(x) if client_sftp_channel in r: x = client_sftp_channel.recv(1024) if len(x) == 0: - break + self.sftp_channel = None self.sftp_channel.send(x) if self.transport.is_active() is False: break - client_shell_channel.close() - self.shell_channel.close() + try: + client_shell_channel.close() + self.shell_channel.close() + except AttributeError as e: + logger.debug(e) + try: + client_sftp_channel.close() + self.sftp_channel.close() + except AttributeError as e: + logger.debug(e) + lxd_interface.destroy_instance(self.instance_name) def set_shell_channel(self, channel):