Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-792

TSocket hides underlying exceptions when open() fails

    XMLWordPrintableJSON

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

          Activity

            People

              Unassigned Unassigned
              tholzer tholzer
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: