From 00a4a772430d1e7e8d2baa076665ad9922bf8fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADnez?= Date: Sun, 13 Feb 2022 10:45:06 -0300 Subject: [PATCH 1/2] timeout on exec_command --- webssh/handler.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/webssh/handler.py b/webssh/handler.py index 9b65d1d..aac2f6a 100644 --- a/webssh/handler.py +++ b/webssh/handler.py @@ -427,15 +427,18 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): for command in commands: try: - _, stdout, _ = ssh.exec_command(command, get_pty=True) + _, stdout, _ = ssh.exec_command(command, get_pty=True, timeout=1) except paramiko.SSHException as exc: logging.info(str(exc)) else: - data = stdout.read() - logging.debug('{!r} => {!r}'.format(command, data)) - result = self.parse_encoding(data) - if result: - return result + try: + data = stdout.read() + logging.debug('{!r} => {!r}'.format(command, data)) + result = self.parse_encoding(data) + if result: + return result + except socket.timeout: + pass logging.warning('Could not detect the default encoding.') return 'utf-8' From c89fcc1da9316cf7bb447071669192f552c1bffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADnez?= Date: Sun, 13 Feb 2022 11:04:13 -0300 Subject: [PATCH 2/2] fix line length --- webssh/handler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webssh/handler.py b/webssh/handler.py index aac2f6a..043e5be 100644 --- a/webssh/handler.py +++ b/webssh/handler.py @@ -427,7 +427,9 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): for command in commands: try: - _, stdout, _ = ssh.exec_command(command, get_pty=True, timeout=1) + _, stdout, _ = ssh.exec_command(command, + get_pty=True, + timeout=1) except paramiko.SSHException as exc: logging.info(str(exc)) else: