Details
Description
When opening a socket via Thrift, the exception message simply says:
"Could not connect to localhost:9160"
The underlying OS error is lost. This is a classic example of the anti-pattern called "exception masquerading". The exception handler loses essential information related to the source of the error. This makes troubleshooting difficult.
The problem lies inside TSocket.py, the original socket.error is simply discarded:
try: ... connect() ... except socket.error, e: ... message = 'Could not connect to %s:%d' % (self.host, self.port) raise TTransportException(TTransportException.NOT_OPEN, message)
To reproduce
thrift.transport.TSocket.TSocket().open()
Excpected behaviour:
The TTransportException should carry as much information as possible relating to the original error, e.g.:
Could not connect to (localhost:9090): (<class 'socket.error'>, error(111, 'Connection refused'))
The TTransportException should carry the real exception it was trying to hide as a member variable so that the caller can take appropriate action in case of transient failures (e.g. EINTR).
Attachments
Issue Links
- relates to
-
THRIFT-793 TSocket doesn't handle socket.gaierror on open()
- Open
-
THRIFT-794 TSocket doesn't handle socket.error on recv() & send()
- Open