From d74b1790d1c95ce372e96f09b7fab33cb192d4fc Mon Sep 17 00:00:00 2001 From: Chris Hines <chris.hines@monash.edu> Date: Tue, 2 Mar 2021 10:54:58 +1100 Subject: [PATCH] use HTTP status 599 to signify an SSH timeout --- tes/apiendpoints.py | 7 +++++-- tes/sshwrapper/__init__.py | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tes/apiendpoints.py b/tes/apiendpoints.py index ccc49e1..775051c 100644 --- a/tes/apiendpoints.py +++ b/tes/apiendpoints.py @@ -10,6 +10,7 @@ import flask_restful from . import api, app from .sshwrapper import Ssh, SshAgentException, SftpPermissionException, SftpException, SshCtrlException, SshExecException from .tunnelstat import SSHSession +import subprocess class AppParamsException(Exception): pass @@ -228,8 +229,10 @@ def wrap_execute(sess, host, user, cmd, bastion=None,stdin=None, sshport="22", b return apiabort(401,message="".format(host)) # This exception is raised if the remove command had a non-zero return code except SshExecException as e: - return apiabort(400,message="{}".format(e)) + return apiabort(400, message="{}".format(e)) # Any other exceptions. This should never be reached. + except subprocess.TimedoutExpired as e: + return apiabort(599, message="{}".format(e)) except Exception as e: import traceback logger.error('JobStat.get: Exception {}'.format(e)) @@ -477,7 +480,7 @@ class AppLaunch(Resource): logger.error(e) logger.error(traceback.format_exc()) #flask_restful.abort(500,message="AppUrl failed in some unexpected way") - return apiabort(500,message="AppUrl failed in some unexpected way") + return apiabort(500,message="AppLaunc failed in some unexpected way") logger.debug('application launched, returning') return None, 200 diff --git a/tes/sshwrapper/__init__.py b/tes/sshwrapper/__init__.py index 9e5e823..c43b0c6 100644 --- a/tes/sshwrapper/__init__.py +++ b/tes/sshwrapper/__init__.py @@ -337,7 +337,8 @@ class Ssh: except subprocess.TimeoutExpired as e: logger.debug('cmd timed out') logger.debug("exception execute") - raise SshExecException(message="A program timed out on the backend server") + raise e + #raise SshExecException(message="A program timed out on the backend server") if exec_p.returncode == 255: logger.error(stderr) sess.kill() -- GitLab