This reverts commit 81553263ab
.
This fixes a regression with Windows port detection which led to port
collisions not being fixed on `vagrant up`.
PR #8517 changed `IsPortOpen#is_port_open?` to rescue
Errno::EADDRNOTAVAIL, but when we merged it into master, there was code
in `HandleForwardedPortCollisions#port_check` that depended on that
error bubbling up.
This commit is contained in:
parent
85065c3746
commit
ade076cabb
|
@ -30,8 +30,7 @@ module Vagrant
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
rescue Timeout::Error, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, \
|
rescue Timeout::Error, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, \
|
||||||
Errno::ENETUNREACH, Errno::EACCES, Errno::ENOTCONN, \
|
Errno::ENETUNREACH, Errno::EACCES, Errno::ENOTCONN
|
||||||
Errno::EADDRNOTAVAIL
|
|
||||||
# Any of the above exceptions signal that the port is closed.
|
# Any of the above exceptions signal that the port is closed.
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,7 +75,8 @@ describe Vagrant::Action::Builtin::HandleForwardedPortCollisions do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should check if host port is in use" do
|
it "should check if host port is in use" do
|
||||||
expect(instance).to receive(:is_forwarded_already).and_return false
|
expect(instance).to receive(:is_forwarded_already).and_return(false)
|
||||||
|
expect(instance).to receive(:is_port_open?).and_return(false)
|
||||||
instance.call(env)
|
instance.call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -148,7 +149,7 @@ describe Vagrant::Action::Builtin::HandleForwardedPortCollisions do
|
||||||
let(:host_port){ 8080 }
|
let(:host_port){ 8080 }
|
||||||
|
|
||||||
it "should check if the port is open" do
|
it "should check if the port is open" do
|
||||||
expect(instance).to receive(:is_port_open?).with(host_ip, host_port).and_return true
|
expect(instance).to receive(:is_port_open?).with(host_ip, host_port).and_return(true)
|
||||||
instance.send(:port_check, host_ip, host_port)
|
instance.send(:port_check, host_ip, host_port)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -156,13 +157,13 @@ describe Vagrant::Action::Builtin::HandleForwardedPortCollisions do
|
||||||
let(:host_ip){ nil }
|
let(:host_ip){ nil }
|
||||||
|
|
||||||
it "should set host_ip to 0.0.0.0 when unset" do
|
it "should set host_ip to 0.0.0.0 when unset" do
|
||||||
expect(instance).to receive(:is_port_open?).with("0.0.0.0", host_port).and_return true
|
expect(instance).to receive(:is_port_open?).with("0.0.0.0", host_port).and_return(true)
|
||||||
instance.send(:port_check, host_ip, host_port)
|
instance.send(:port_check, host_ip, host_port)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set host_ip to 127.0.0.1 when 0.0.0.0 is not available" do
|
it "should set host_ip to 127.0.0.1 when 0.0.0.0 is not available" do
|
||||||
expect(instance).to receive(:is_port_open?).with("0.0.0.0", host_port).and_raise Errno::EADDRNOTAVAIL
|
expect(instance).to receive(:is_port_open?).with("0.0.0.0", host_port).and_raise(Errno::EADDRNOTAVAIL)
|
||||||
expect(instance).to receive(:is_port_open?).with("127.0.0.1", host_port).and_return true
|
expect(instance).to receive(:is_port_open?).with("127.0.0.1", host_port).and_return(true)
|
||||||
instance.send(:port_check, host_ip, host_port)
|
instance.send(:port_check, host_ip, host_port)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,5 +49,15 @@ describe Vagrant::Util::IsPortOpen do
|
||||||
# best, really.
|
# best, really.
|
||||||
expect(klass.is_port_open?("127.0.0.1", closed_port)).not_to be
|
expect(klass.is_port_open?("127.0.0.1", closed_port)).not_to be
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should handle connection refused" do
|
||||||
|
expect(TCPSocket).to receive(:new).with("0.0.0.0", closed_port).and_raise(Errno::ECONNREFUSED)
|
||||||
|
expect(klass.is_port_open?("0.0.0.0", closed_port)).to be(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should raise an error if cannot assign requested address" do
|
||||||
|
expect(TCPSocket).to receive(:new).with("0.0.0.0", open_port).and_raise(Errno::EADDRNOTAVAIL)
|
||||||
|
expect { klass.is_port_open?("0.0.0.0", open_port) }.to raise_error(Errno::EADDRNOTAVAIL)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue