PROTON-1721 [ruby] resovler errors are not handled correctly Catch exceptions raised by TCPServer.new/TCPSocket.new and convert into error events.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/c4d5fde7 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/c4d5fde7 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/c4d5fde7 Branch: refs/heads/go1 Commit: c4d5fde71d925f3f44b0e29d672de7b039ee709f Parents: f252b2f Author: Alan Conway <[email protected]> Authored: Fri Dec 15 11:34:44 2017 -0500 Committer: Alan Conway <[email protected]> Committed: Fri Dec 15 16:59:23 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/c4d5fde7/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/c4d5fde7/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: [email protected] For additional commands, e-mail: [email protected]
