Merge pull request #13606 from allisonlarson/catch-io-timeout-error

Catch IO::Timeout when waiting for communicator
This commit is contained in:
Allison Larson 2025-03-13 10:18:52 -07:00 committed by GitHub
commit d1f699b76b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 15 additions and 1 deletions

View file

@ -11,6 +11,7 @@ Vagrant.require "log4r"
Vagrant.require "vagrant/patches/log4r"
Vagrant.require "vagrant/patches/net-ssh"
Vagrant.require "vagrant/patches/rubygems"
Vagrant.require "vagrant/patches/timeout_error"
# Set our log levels and include trace
Vagrant.require 'log4r/configurator'

View file

@ -0,0 +1,5 @@
# Adds an IO::TimeoutError for versions of ruby where it isn't defined (< 3.2).
if !defined?(IO::TimeoutError)
class IO::TimeoutError < StandardError
end
end

View file

@ -539,7 +539,7 @@ module VagrantPlugins
rescue Errno::EACCES
# This happens on connect() for unknown reasons yet...
raise Vagrant::Errors::SSHConnectEACCES
rescue Errno::ETIMEDOUT, Timeout::Error
rescue Errno::ETIMEDOUT, Timeout::Error, IO::TimeoutError
# This happens if we continued to timeout when attempting to connect.
raise Vagrant::Errors::SSHConnectionTimeout
rescue Net::SSH::AuthenticationFailed

View file

@ -181,6 +181,8 @@ module VagrantPlugins
raise Errors::SSLError, message: exception.message
when HTTPClient::TimeoutError
raise Errors::ConnectionTimeout, message: exception.message
when IO::TimeoutError
raise Errors::ConnectionTimeout
when Errno::ETIMEDOUT
raise Errors::ConnectionTimeout
# This is raised if the connection timed out

View file

@ -173,6 +173,12 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
expect(subject.cmd("dir").exitcode).to eq(0)
end
end
it "should catch timeout errors" do
expect(connection).to receive(:shell).with(:cmd, { })
expect(shell).to receive(:run).with("hostname").and_raise(IO::TimeoutError)
expect { subject.cmd("hostname") }.to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::ConnectionTimeout)
end
end
describe ".wql" do