core: more liberally release port leases

This commit is contained in:
Mitchell Hashimoto 2014-04-24 22:59:17 -07:00
parent 5eb1dfbddd
commit 84f889e801
1 changed files with 20 additions and 0 deletions

View File

@ -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