OpenSSL exceptions in SocketOperation are being converted to socket.error exceptions. This patch changes this, and throws them as is.
This patch also looks at all the callers who catch socket.error exceptions, and makes them also catch OpenSSL exceptions. This means that the only behavior change will be more informative errors. Specifically, all the exceptions that were caught before are now still caught. Signed-off-by: BSRK Aditya <[email protected]> --- lib/http/__init__.py | 13 +++++++------ lib/http/server.py | 5 +++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/http/__init__.py b/lib/http/__init__.py index b01d6fb..e6e7d00 100644 --- a/lib/http/__init__.py +++ b/lib/http/__init__.py @@ -449,7 +449,7 @@ def SocketOperation(sock, op, arg1, timeout): return "" # SSL_shutdown shouldn't return SSL_ERROR_ZERO_RETURN - raise socket.error(err.args) + raise err except OpenSSL.SSL.SysCallError, err: if op == SOCKOP_SEND: @@ -467,10 +467,7 @@ def SocketOperation(sock, op, arg1, timeout): # opened. raise HttpSessionHandshakeUnexpectedEOF(err.args) - raise socket.error(err.args) - - except OpenSSL.SSL.Error, err: - raise socket.error(err.args) + raise err except socket.error, err: if err.args and err.args[0] == errno.EAGAIN: @@ -505,7 +502,7 @@ def ShutdownConnection(sock, close_timeout, write_timeout, msgreader, force): # Check whether it's actually closed if not SocketOperation(sock, SOCKOP_RECV, 1, close_timeout): return - except (socket.error, HttpError, HttpSocketTimeout): + except (socket.error, HttpError, HttpSocketTimeout, OpenSSL.SSL.Error): # Ignore errors at this stage pass @@ -520,6 +517,8 @@ def ShutdownConnection(sock, close_timeout, write_timeout, msgreader, force): # Ignore ENOTCONN if not (err.args and err.args[0] == errno.ENOTCONN): raise HttpError("Error while shutting down connection: %s" % err) + except OpenSSL.SSL.Error, err: + raise HttpError("Error while shutting down connection: %s" % err) def Handshake(sock, write_timeout): @@ -537,6 +536,8 @@ def Handshake(sock, write_timeout): raise HttpError("Timeout during SSL handshake") except socket.error, err: raise HttpError("Error in SSL handshake: %s" % err) + except OpenSSL.SSL.Error, err: + raise HttpError("Error in SSL handshake: %s" % err) class HttpSslParams(object): diff --git a/lib/http/server.py b/lib/http/server.py index 835b737..ffa1a3b 100644 --- a/lib/http/server.py +++ b/lib/http/server.py @@ -39,6 +39,7 @@ import socket import time import signal import asyncore +import OpenSSL from ganeti import http from ganeti import utils @@ -455,6 +456,8 @@ class HttpServerRequestExecutor(object): raise http.HttpError("Timeout while reading request") except socket.error, err: raise http.HttpError("Error reading request: %s" % err) + except OpenSSL.SSL.Error, err: + raise http.HttpError("Error reading request: %s" % err) return (msg, reader) @@ -469,6 +472,8 @@ class HttpServerRequestExecutor(object): raise http.HttpError("Timeout while sending response") except socket.error, err: raise http.HttpError("Error sending response: %s" % err) + except OpenSSL.SSL.Error, err: + raise http.HttpError("Error sending response: %s" % err) class HttpServer(http.HttpBase, asyncore.dispatcher): -- 1.7.10.4
