From 84f889e801a18a5ffadd8a88bd102631710c9844 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 24 Apr 2014 22:59:17 -0700 Subject: [PATCH] core: more liberally release port leases --- .../handle_forwarded_port_collisions.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb b/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb index ea462be2f..5425a4221 100644 --- a/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb +++ b/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb @@ -32,6 +32,7 @@ module Vagrant end def call(env) + @leased = [] @machine = env[:machine] # Acquire a process-level lock so that we don't choose a port @@ -46,6 +47,13 @@ module Vagrant end @app.call(env) + + # Always run the recover method so that we release leases + recover(env) + end + + def recover(env) + lease_release end protected @@ -176,10 +184,22 @@ module Vagrant f.write(Time.now.to_i.to_s + "\n") end + # Add to the leased array so we unlease it right away + @leased << port.to_s + # Things look good to us! false end + def lease_release + leasedir = @machine.env.data_dir.join("fp-leases") + + @leased.each do |port| + path = leasedir.join(port) + path.delete if path.file? + end + end + def port_check(port) is_port_open?("127.0.0.1", port) end