Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Spawning a new ssh session for each tunnel in the deployer.

We did that because spawning multiple tunnels per session was crashing intermittently.
By having one new session per tunnel we guarantee that one tunnel won't crash the others.

We also rolled back the SSH tunnel for the director. Encrypted
communication with the director is still to be discussed.
  • Loading branch information...
commit 7a02068d90e4c2f58717da69d625a68fd2c6cbd0 1 parent afd5a84
Jeffrey Peckham and Vinicius Fuentes authored
8 bosh_deployer/lib/deployer/instance_manager.rb
View
@@ -414,18 +414,16 @@ def agent_port
end
def wait_until_agent_ready #XXX >> agent_client
- incoming_tunnel(@registry_port)
- outgoing_tunnel(agent_port)
+ remote_tunnel(@registry_port)
+ local_tunnel(agent_port)
wait_until_ready("agent") { agent.ping }
end
def wait_until_director_ready
port = @apply_spec.director_port
+ url = "http://#{bosh_ip}:#{port}/info"
- outgoing_tunnel(port)
-
- url = "http://127.0.0.1:#{port}/info"
wait_until_ready("director") do
info = Yajl::Parser.parse(HTTPClient.new.get(url).body)
logger.info("Director is ready: #{info.inspect}")
68 bosh_deployer/lib/deployer/instance_manager_helpers.rb
View
@@ -35,19 +35,19 @@ def socket_readable?(ip, port)
socket.close if socket
end
- def incoming_tunnel(port)
- tunnel(port, :incoming)
+ def remote_tunnel(port)
+ tunnel(port, :remote)
end
- def outgoing_tunnel(port)
- tunnel(port, :outgoing)
+ def local_tunnel(port)
+ tunnel(port, :local)
end
private
def tunnel(port, direction)
- @established_sessions ||= {}
- return if @session && @established_sessions[port]
+ @sessions ||= {}
+ return if @sessions[port]
ip = discover_bosh_ip
@@ -56,41 +56,43 @@ def tunnel(port, direction)
sleep @ssh_wait
end
- lo = "127.0.0.1"
- cmd = "ssh -R #{port}:#{lo}:#{port} #{@ssh_user}@#{ip}"
-
- logger.info("Preparing for ssh tunnel: #{cmd}")
- loop do
- begin
- @session = Net::SSH.start(ip, @ssh_user, :keys => [@ssh_key],
- :paranoid => false)
- logger.debug("ssh #{@ssh_user}@#{ip}: ESTABLISHED")
- break
- rescue => e
- logger.debug("ssh start #{@ssh_user}@#{ip} failed: #{e.inspect}")
- sleep 1
+ if @sessions[port].nil?
+ logger.info("Starting SSH session for port forwarding to #{@ssh_user}@#{ip}...")
+ loop do
+ begin
+ @sessions[port] = Net::SSH.start(ip, @ssh_user, :keys => [@ssh_key],
+ :paranoid => false)
+ logger.debug("ssh #{@ssh_user}@#{ip}: ESTABLISHED")
+ break
+ rescue => e
+ logger.debug("ssh start #{@ssh_user}@#{ip} failed: #{e.inspect}")
+ sleep 1
+ end
end
- end unless @session
-
- if direction == :incoming
- @session.forward.remote(port, lo, port)
- elsif direction == :outgoing
- @session.forward.local(port, lo, port)
end
- @established_sessions[port] = true
+ lo = "127.0.0.1"
+ case direction
+ when :remote
+ @sessions[port].forward.remote(port, lo, port)
+ when :local
+ @sessions[port].forward.local(port, lo, port)
+ else
+ raise ArgumentError, "Invalid direction for ssh tunnel: #{direction}"
+ end
- logger.info("`#{cmd}` started: OK")
+ logger.info("SSH #{direction} forwarding for port #{port} started: OK")
Thread.new do
- begin
- @session.loop { true }
- rescue IOError => e
- logger.debug("`#{cmd}` terminated: #{e.inspect}")
- @session = nil
+ while @sessions[port]
+ begin
+ @sessions[port].loop { true }
+ rescue IOError => e
+ logger.debug("SSH session #{@sessions[port].inspect} forwarding for port #{port} terminated: #{e.inspect}")
+ @sessions.delete(port)
+ end
end
end
end
-
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.