Hi,
I'm trying to use Net::SSH::Multi. http://net-ssh.rubyforge.org/
It seems that ruby have difficulties to catch exception in multi threaded mode, any hint?
the doc said, if we put (:on_error => :warn) it shouldn't fail, be the exception begin/rescue bloc did catch the exception, here Errno::EHOSTUNREACH
/var/lib/gems/1.8/gems/net-ssh-multi-1.0.0/lib/net/ssh/./multi/session.rb
468 def next_session(server, force=false) #:nodoc:
[...]
482 begin
483 server.new_session
484 rescue Exception => e
485 server.fail!
486 @session_mutex.synchronize { @open_connections -= 1 }
487
488 case on_error
489 when :ignore then
490 # do nothing
491 when :warn then
492 warn("error connecting to #{server}: #{e.class} (#{e.message})")
493 when Proc then
494 go = catch(:go) { on_error.call(server); nil }
495 case go
496 when nil, :ignore then # nothing
497 when :retry then retry
498 when :raise then raise
499 else warn "unknown 'go' command: #{go.inspect}"
500 end
501 else
502 raise
503 end
504
505 return nil
506 end
[...]
As we can test, we are able to catch the exception at to level, could you confirm its tread related?
require 'rubygems'
require 'net/ssh/multi'
Net::SSH::Multi.start(:on_error => :warn) do |session|
# define the servers we want to use
session.use 'root@server-04'
session.use 'root@server-07' # doesn't exist
session.use 'root@server-08'
# execute commands on all servers
begin
session.exec( "hostname" )
rescue Exception => e
p "main:#{e}"
end
# run the aggregated event loop
session.loop
end
ruby 1.8.5 (2006-08-25) [x86_64-linux]
Regards,
Sylvain.