Skip to content
Browse files

Bug 917457

When a local port is already bound by another process, we see
Errno::EACCES. Rescue this and try the next port.
  • Loading branch information...
1 parent 6aaff42 commit 309123696a1bb4703c6d66002d031c5d3dd1a2b1 @BanzaiMan BanzaiMan committed
Showing with 17 additions and 2 deletions.
  1. +2 −2 lib/rhc/commands/port_forward.rb
  2. +15 −0 spec/rhc/commands/port_forward_spec.rb
View
4 lib/rhc/commands/port_forward.rb
@@ -130,8 +130,8 @@ def run(app)
debug args.inspect
ssh.forward.local(*args)
fs.bound = true
- rescue Errno::EADDRINUSE
- debug "trying local port #{fs.port_from}"
+ rescue Errno::EADDRINUSE, Errno::EACCES => e
+ warn "#{e} while forwarding port #{fs.port_from}. Trying local port #{fs.port_from+1}"
fs.port_from += 1
rescue Timeout::Error, Errno::EADDRNOTAVAIL, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Net::SSH::AuthenticationFailed => e
given_up = true
View
15 spec/rhc/commands/port_forward_spec.rb
@@ -116,6 +116,21 @@
it { run_output.should include("Ending port forward") }
end
+ context 'when local port is already bound' do
+ before(:each) do
+ Net::SSH.should_receive(:start).with(@uri.host, @uri.user).and_yield(@ssh).twice
+ @ssh.should_receive(:exec!).with("rhc-list-ports").and_yield(nil, :stderr, 'mysql -> 127.0.0.1:3306')
+ forward = mock(Net::SSH::Service::Forward)
+ @ssh.should_receive(:forward).at_least(2).and_return(forward)
+ forward.should_receive(:local).with(3306, '127.0.0.1', 3306).and_raise(Errno::EACCES)
+ forward.should_receive(:local).with(3307, '127.0.0.1', 3306)
+ @ssh.should_receive(:loop).and_raise(Interrupt.new)
+ end
+ it 'should bind to a higher port' do
+ run_output.should include("3307")
+ end
+ end
+
context 'when host refuses connection' do
before(:each) do
Net::SSH.should_receive(:start).with(@uri.host, @uri.user).and_yield(@ssh).twice

0 comments on commit 3091236

Please sign in to comment.
Something went wrong with that request. Please try again.