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] 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'