You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/02/18 17:07:23 UTC

[3/3] thrift git commit: THRIFT-3641 Ruby client should try to connect to every result of getaddrinfo Client: Ruby Patch: Nobuaki Sukegawa

THRIFT-3641 Ruby client should try to connect to every result of getaddrinfo
Client: Ruby
Patch: Nobuaki Sukegawa

This closes #872


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/e1e09c79
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/e1e09c79
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/e1e09c79

Branch: refs/heads/master
Commit: e1e09c7967aa7149ae291de9da744142e67a3806
Parents: 0433d17
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Thu Feb 18 01:03:07 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Fri Feb 19 01:06:05 2016 +0900

----------------------------------------------------------------------
 lib/rb/lib/thrift/transport/socket.rb | 32 ++++++++++++++++--------------
 lib/rb/spec/socket_spec.rb            |  2 +-
 test/known_failures_Linux.json        |  1 -
 test/tests.json                       |  3 +--
 4 files changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/e1e09c79/lib/rb/lib/thrift/transport/socket.rb
----------------------------------------------------------------------
diff --git a/lib/rb/lib/thrift/transport/socket.rb b/lib/rb/lib/thrift/transport/socket.rb
index 2b7ca09..517d112 100644
--- a/lib/rb/lib/thrift/transport/socket.rb
+++ b/lib/rb/lib/thrift/transport/socket.rb
@@ -33,26 +33,28 @@ module Thrift
     attr_accessor :handle, :timeout
 
     def open
-      begin
-        addrinfo = ::Socket::getaddrinfo(@host, @port, nil, ::Socket::SOCK_STREAM).first
-        @handle = ::Socket.new(addrinfo[4], ::Socket::SOCK_STREAM, 0)
-        @handle.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
-        sockaddr = ::Socket.sockaddr_in(addrinfo[1], addrinfo[3])
+      for addrinfo in ::Socket::getaddrinfo(@host, @port, nil, ::Socket::SOCK_STREAM) do
         begin
-          @handle.connect_nonblock(sockaddr)
-        rescue Errno::EINPROGRESS
-          unless IO.select(nil, [ @handle ], nil, @timeout)
-            raise TransportException.new(TransportException::NOT_OPEN, "Connection timeout to #{@desc}")
-          end
+          socket = ::Socket.new(addrinfo[4], ::Socket::SOCK_STREAM, 0)
+          socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
+          sockaddr = ::Socket.sockaddr_in(addrinfo[1], addrinfo[3])
           begin
-            @handle.connect_nonblock(sockaddr)
-          rescue Errno::EISCONN
+            socket.connect_nonblock(sockaddr)
+          rescue Errno::EINPROGRESS
+            unless IO.select(nil, [ socket ], nil, @timeout)
+              next
+            end
+            begin
+              socket.connect_nonblock(sockaddr)
+            rescue Errno::EISCONN
+            end
           end
+          return @handle = socket
+        rescue StandardError => e
+          next
         end
-        @handle
-      rescue StandardError => e
-        raise TransportException.new(TransportException::NOT_OPEN, "Could not connect to #{@desc}: #{e}")
       end
+      raise TransportException.new(TransportException::NOT_OPEN, "Could not connect to #{@desc}: #{e}")
     end
 
     def open?

http://git-wip-us.apache.org/repos/asf/thrift/blob/e1e09c79/lib/rb/spec/socket_spec.rb
----------------------------------------------------------------------
diff --git a/lib/rb/spec/socket_spec.rb b/lib/rb/spec/socket_spec.rb
index e6b6732..8e1ef50 100644
--- a/lib/rb/spec/socket_spec.rb
+++ b/lib/rb/spec/socket_spec.rb
@@ -35,7 +35,7 @@ describe 'Socket' do
     it_should_behave_like "a socket"
 
     it "should raise a TransportException when it cannot open a socket" do
-      ::Socket.should_receive(:new).and_raise(StandardError)
+      ::Socket.should_receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]])
       lambda { @socket.open }.should raise_error(Thrift::TransportException) { |e| e.type.should == Thrift::TransportException::NOT_OPEN }
     end
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/e1e09c79/test/known_failures_Linux.json
----------------------------------------------------------------------
diff --git a/test/known_failures_Linux.json b/test/known_failures_Linux.json
index 9ca31c4..a27b27a 100644
--- a/test/known_failures_Linux.json
+++ b/test/known_failures_Linux.json
@@ -35,7 +35,6 @@
   "cpp-perl_binary_buffered-ip-ssl",
   "cpp-perl_binary_framed-ip-ssl",
   "cpp-py_binary-accel_framed-ip-ssl",
-  "cpp-rb_binary-accel_framed-ip",
   "csharp-cpp_binary_buffered-ip-ssl",
   "csharp-cpp_binary_framed-ip-ssl",
   "csharp-cpp_compact_buffered-ip-ssl",

http://git-wip-us.apache.org/repos/asf/thrift/blob/e1e09c79/test/tests.json
----------------------------------------------------------------------
diff --git a/test/tests.json b/test/tests.json
index 1eeb224..902d2fe 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -289,8 +289,7 @@
       "timeout": 5,
       "command": [
         "ruby",
-        "../integration/TestClient.rb",
-        "--host=127.0.0.1"
+        "../integration/TestClient.rb"
       ]
     },
     "transports": [