amadain
amadain

Reputation: 2836

ssh proxy script runs in ruby but not in jruby

I have a ruby script that uses the net::ssh gem.

Its a simple script to tunnel through a jump-off server to a destination box. The box is only visible to the jump-off server. Here is the script:

require 'net/ssh/proxy/command'
require "net/ssh"

class TestTunnel
  def initialize
    proxy = Net::SSH::Proxy::Command.new('ssh [email protected] nc %h %p 2>/dev/null')
    p "proxy gotten"
    Net::SSH.start("host1", "admin", :password => "admin", :proxy => proxy) do |ssh|
      hostname = ssh.exec!("hostname")
      p "In #{hostname}"
    end
  end
end
b=TestTunnel.new

The issue is the script runs in ruby but not in jruby. My framework runs off jruby so I need to use it with jruby.

My solution was to call a bash script from my jruby script to setup the tunnel and run commands there but I would rather have everything done within jruby.

Here are the errors I get:

~/src/main/ruby$ jruby --1.9 scripts/test_tunnel.rb 
"proxy gotten"
IO::EAGAINWaitReadable: Resource temporarily unavailable - errno backtraces disabled; run with -Xerrno.backtrace=true to enable

And when I run in ruby:

~/src/main/ruby$ ruby scripts/test_tunnel.rb 
"proxy gotten"
"In vz-int-api02\n"
~/src/main/ruby$ 

When I run with -Xerrno.backtrace=true I can see that jruby is 1.7.9 and I can see that its using ruby 1.9:

~/src/main/ruby$ jruby -Xerrno.backtrace=true --1.9 scripts/test_tunnel.rb
"proxy gotten"
IO::EAGAINWaitReadable: Resource temporarily unavailable - 
  read_nonblock at org/jruby/RubyIO.java:2856
           recv at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/proxy/command.rb:75
           fill at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/buffered_io.rb:65
    next_packet at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/packet_stream.rb:88
   poll_message at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:183
           loop at org/jruby/RubyKernel.java:1519
   poll_message at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178
           wait at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:215
           loop at org/jruby/RubyKernel.java:1519
           wait at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:213
     initialize at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:87
          start at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/net-ssh-2.9.2/lib/net/ssh.rb:207
     initialize at scripts/test_tunnel.rb:8
     (root) at scripts/test_tunnel.rb:15
~/src/main/ruby$ jruby -Xerrno.backtrace=true --1.9 --version
jruby 1.7.9 (1.9.3p392) 2013-12-06 87b108a on Java HotSpot(TM) 64-Bit Server VM 1.8.0_72-b15 +indy [linux-amd64]
~/src/main/ruby$

Is there any way to get this to run in jruby like it does in ruby or is my solution to call a bash script from within jruby the only way to do this?

A

Upvotes: 3

Views: 241

Answers (1)

Frederick Cheung
Frederick Cheung

Reputation: 84114

This sounds a lot like this bug in net-ssh that was fixed in net-ssh 3.0.2.

The commit message that closed that issue t was "Bugfix: proxy command was using nonblocking io api incorrectly causing rare IO::EAGAIN errors" which sounds like exactly what you are getting.

Upvotes: 2

Related Questions