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

TNonblockingSocket connects without a timeout

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.5
    • Java - Library
    • None

    Description

      Unlike TSocket which takes a timeout in its constructor and uses it as both the connect timeout and the so timeout, TNonblockingSocket only supports a setTimeout method which sets the so timeout but doesn't apply the timeout to the connect operation. Instead, it calls the convenience method SocketChannel.open in its constructor, which calls a blocking, connection-free connect before we set the socket into non-blocking mode or set an so timeout on it.

      A solution would be to do something like the following:

      SocketChannel socketChannel = SocketChannel.open();
      this.socket_ = socketChannel.socket();
      socket_.setSoTimeout(timeout_);
      socket_.connect(new InetSocketAddress(host, port), timeout_);
      socketChannel.configureBlocking(false);

      That's a bit weird since in TSocket we do the blocking connect in the open() method instead of the constructor, but it seems like a better fix than to refactor all the non-blocking stuff to also call open().

      Also, the initSocket() method in TNonblockingSocket is invalid entirely (although unreachable) as it would overwrite the Socket from the channel with a new, unconnected blocking one.

      Attachments

        1. thrift-843.patch
          1 kB
          Bryan Duxbury

        Activity

          People

            bryanduxbury Bryan Duxbury
            ericcj Eric Jensen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: