Skip to content

Commit

Permalink
Check if a port is open prior to forwarding [hashicorpGH-821]
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Mar 23, 2012
1 parent d08a65e commit c1445a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,8 @@
- Chef-solo provisioner now supports encrypted data bags. [GH-816]
- Enable the NAT DNS proxy by default, allowing your DNS to continue
working when you switch networks. [GH-834]
- Checking for port forwarding collisions also checks for other applications
that are potentially listening on that port as well. [GH-821]

## 1.0.1 (March 11, 2012)

Expand Down
6 changes: 5 additions & 1 deletion lib/vagrant/action/vm/check_port_collisions.rb
@@ -1,9 +1,13 @@
require "vagrant/util/is_port_open"

module Vagrant
module Action
module VM
# Action that checks to make sure there are no forwarded port collisions,
# and raises an exception if there is.
class CheckPortCollisions
include Util::IsPortOpen

def initialize(app, env)
@app = app
end
Expand All @@ -29,7 +33,7 @@ def call(env)
hostport = options[:hostport].to_i
hostport = current[options[:name]] if current.has_key?(options[:name])

if existing.include?(hostport)
if existing.include?(hostport) || is_port_open?("localhost", hostport)
# We have a collision! Handle it
send("handle_#{handler}".to_sym, options, existing)
end
Expand Down

0 comments on commit c1445a0

Please sign in to comment.