You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/12/15 21:59:11 UTC

[4/5] qpid-proton git commit: WIP: Fix bad connect/listen host resolve error

WIP: Fix bad connect/listen host resolve error


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/5cb9775d
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/5cb9775d
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/5cb9775d

Branch: refs/heads/ruby-api
Commit: 5cb9775d5924198b17e189f8692a265181090388
Parents: f252b2f
Author: Alan Conway <ac...@redhat.com>
Authored: Fri Dec 15 11:34:44 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Dec 15 11:34:44 2017 -0500

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/container.rb   | 26 +++++++++++++++++++--
 proton-c/bindings/ruby/tests/test_container.rb | 14 +++++++++--
 2 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5cb9775d/proton-c/bindings/ruby/lib/core/container.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/container.rb b/proton-c/bindings/ruby/lib/core/container.rb
index 242356f..5dc9d60 100644
--- a/proton-c/bindings/ruby/lib/core/container.rb
+++ b/proton-c/bindings/ruby/lib/core/container.rb
@@ -41,6 +41,18 @@ module Qpid::Proton
       end
     end
 
+    # Used as the @io when a socket cannot be created due to an erro (e.g resolver fails)
+    # Saves the error and raises it in on_readable so it can be reported via normal channels.
+     class BrokenSocket
+       def initialize(msg) @error = IOError.new(msg); end
+       [:read_nonblock, :write_nonblock, :accept].each do |m|
+         define_method(m) { |*args| raise @error }
+       end
+       [:close_read, :close_write, :close].each do |m|
+         define_method(m) {}
+       end
+    end
+
     class ListenTask < Listener
 
       def initialize(io, handler, container)
@@ -177,7 +189,12 @@ module Qpid::Proton
         opts[:password] ||= url.password
       end
       # TODO aconway 2017-10-26: Use SSL for amqps URLs
-      connect_io(TCPSocket.new(url.host, url.port), opts)
+      socket = begin
+                 TCPSocket.new(url.host, url.port)
+               rescue => e
+                 BrokenSocket.new("connect(#{url}): #{e}")
+               end
+      connect_io(socket, opts)
     end
 
     # Open an AMQP protocol connection on an existing {IO} object
@@ -202,7 +219,12 @@ module Qpid::Proton
       not_stopped
       url = Qpid::Proton::uri url
       # TODO aconway 2017-11-01: amqps, SSL
-      listen_io(TCPServer.new(url.host, url.port), handler)
+      server = begin
+                 TCPServer.new(url.host, url.port)
+               rescue => e
+                 BrokenSocket.new("listen(#{url}): #{e}")
+               end
+      listen_io(server, handler)
     end
 
     # Listen for incoming AMQP connections on an existing server socket.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5cb9775d/proton-c/bindings/ruby/tests/test_container.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_container.rb b/proton-c/bindings/ruby/tests/test_container.rb
index 044ebf4..d8bd52c 100644
--- a/proton-c/bindings/ruby/tests/test_container.rb
+++ b/proton-c/bindings/ruby/tests/test_container.rb
@@ -149,6 +149,16 @@ class ContainerTest < Minitest::Test
     assert_nil l.condition
     assert_nil conn.condition
   end
+
+  def test_bad_host
+    cont = Container.new(__method__)
+    l = cont.listen("badlisten.example.com:999")
+    c = cont.connect("badconnect.example.com:999")
+    cont.run
+    assert_match(/badlisten.example.com:999/, l.condition.description)
+    assert_match(/badconnect.example.com:999/, c.transport.condition.description)
+  end
+
 end
 
 
@@ -201,8 +211,8 @@ mech_list: EXTERNAL DIGEST-MD5 SCRAM-SHA-1 CRAM-MD5 PLAIN ANONYMOUS
                   ")
         end
         # Tell proton library to use the new configuration
-        SASL.config_path(conf_dir)
-        SASL.config_name(conf_name)
+        SASL.config_path =  conf_dir
+        SASL.config_name = conf_name
       end
     end
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org