Beispiel #1
0
      def wrapper(*args, **kwargs):
        try:
          try:
            # Poke it to see if it's closed on the other end. This can happen if a connection
            # sits in the connection pool longer than the read timeout of the server.
            sock = _grab_transport_from_wrapper(superclient.transport).handle
            if sock and create_synchronous_io_multiplexer().read([sock]):
              # the socket is readable, meaning there is either data from a previous call
              # (i.e our protocol is out of sync), or the connection was shut down on the
              # remote side. Either way, we need to reopen the connection.
              # If the socket was closed remotely, btw, socket.read() will return
              # an empty string.  This is a fairly normal condition, btw, since
              # there are timeouts on both the server and client sides.
              superclient.transport.close()
              superclient.transport.open()

            superclient.set_timeout(self.conf.timeout_seconds)
            return res(*args, **kwargs)
          except TApplicationException, e:
            # Unknown thrift exception... typically IO errors
            logging.info("Thrift saw an application exception: " + str(e), exc_info=False)
            raise StructuredException('THRIFTAPPLICATION', str(e), data=None, error_code=502)
          except socket.error, e:
            logging.info("Thrift saw a socket error: " + str(e), exc_info=False)
            raise StructuredException('THRIFTSOCKET', str(e), data=None, error_code=502)
Beispiel #2
0
    def wrapper(*args, **kwargs):
      superclient = _connection_pool.get_client(self.conf)

      try:
        attr = getattr(superclient, attr_name)

        try:
          # Poke it to see if it's closed on the other end. This can happen if a connection
          # sits in the connection pool longer than the read timeout of the server.
          sock = self.conf.transport_mode != 'http' and _grab_transport_from_wrapper(superclient.transport).handle
          if sock and create_synchronous_io_multiplexer().read([sock]):
            # the socket is readable, meaning there is either data from a previous call
            # (i.e our protocol is out of sync), or the connection was shut down on the
            # remote side. Either way, we need to reopen the connection.
            # If the socket was closed remotely, btw, socket.read() will return
            # an empty string.  This is a fairly normal condition, btw, since
            # there are timeouts on both the server and client sides.
            superclient.transport.close()
            superclient.transport.open()

          superclient.set_timeout(self.conf.timeout_seconds)

          return attr(*args, **kwargs)
        except TApplicationException, e:
          # Unknown thrift exception... typically IO errors
          logging.info("Thrift saw an application exception: " + str(e), exc_info=False)
          raise StructuredException('THRIFTAPPLICATION', str(e), data=None, error_code=502)
        except socket.error, e:
          logging.info("Thrift saw a socket error: " + str(e), exc_info=False)
          raise StructuredException('THRIFTSOCKET', str(e), data=None, error_code=502)