diff --git a/Project.toml b/Project.toml index 2f7ad8af12..0f964610d4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "AWS" uuid = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc" license = "MIT" -version = "1.90.0" +version = "1.90.1" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/src/IMDS.jl b/src/IMDS.jl index a26e6d93b5..6361cc4202 100644 --- a/src/IMDS.jl +++ b/src/IMDS.jl @@ -101,7 +101,7 @@ function _http_request(args...; status_exception=true, kwargs...) # and connections will fail. On EC2 instances where IMDS is disabled a HTTP 403 is # returned. # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html#instance-metadata-returns - if e isa ConnectError || e isa StatusError && e.status == 403 + if is_connection_exception(e) || e isa StatusError && e.status == 403 throw(IMDSUnavailable()) #! format: off @@ -118,6 +118,14 @@ function _http_request(args...; status_exception=true, kwargs...) return response end +is_connection_exception(e::ConnectError) = true +is_connection_exception(e::Exception) = false + +# https://github.com/JuliaCloud/AWS.jl/issues/649 +function is_connection_exception(e::HTTP.Exceptions.RequestError) + return e.error == Base.IOError("read: connection timed out (ETIMEDOUT)", -110) +end + """ get([session::Session], path::AbstractString) -> Union{String, Nothing} diff --git a/test/IMDS.jl b/test/IMDS.jl index ac61bcc123..75bf6a1664 100644 --- a/test/IMDS.jl +++ b/test/IMDS.jl @@ -82,6 +82,21 @@ function _imds_patch(router::HTTP.Router=HTTP.Router(); listening=true, enabled= end @testset "IMDS" begin + @testset "is_connection_exception" begin + url = "http://169.254.169.254/latest/api/token" + connect_timeout = HTTP.ConnectionPool.ConnectTimeout("169.254.169.254", 80) + e = HTTP.Exceptions.ConnectError(url, connect_timeout) + @test IMDS.is_connection_exception(e) + + request = HTTP.Request("PUT", "/latest/api/token", [], HTTP.nobody) + io_error = Base.IOError("read: connection timed out (ETIMEDOUT)", -110) + e = HTTP.Exceptions.RequestError(request, io_error) + @test IMDS.is_connection_exception(e) + + e = ErrorException("non-connection error") + @test !IMDS.is_connection_exception(e) + end + @testset "refresh_token!" begin # Running outside of an EC2 instance apply(_imds_patch(; listening=false)) do