Skip to content

Commit

Permalink
mark recoverability of DNS erros correctly
Browse files Browse the repository at this point in the history
This changes HTTP client to not retry on certain DNS errors. From the [list of possible DNS errors](https://github.com/JuliaLang/julia/blob/ec8df3da3597d0acd503ff85ac84a5f8f73f625b/stdlib/Sockets/src/addrinfo.jl#L108-L112) only EAI_AGAIN may be recoverable. This also changes the error code comparison to use `UV_EAI_AGAIN`, because that is what a [DNSError instance would contain](https://github.com/JuliaLang/julia/blob/ec8df3da3597d0acd503ff85ac84a5f8f73f625b/stdlib/Sockets/src/addrinfo.jl#L108-L112).
  • Loading branch information
tanmaykm committed Aug 2, 2023
1 parent 10182c0 commit f4bd74b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/clientlayers/RetryRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ increasing delay is introduced between attempts to avoid exacerbating network
congestion.
By default, requests that have a retryable body, where the request wasn't written
or is idempotent will be retries. If the request is made and a response is received
or is idempotent will be retried. If the request is made and a response is received
with a status code of 403, 408, 409, 429, or 5xx, the request will be retried.
`retries` controls the # of total retries that will be attempted.
Expand Down Expand Up @@ -76,10 +76,17 @@ function retrylayer(handler)
end
end

const EAI_AGAIN = 2
isrecoverable(ex) = true
isrecoverable(ex::CapturedException) = isrecoverable(ex.ex)
isrecoverable(ex::ConnectError) = ex.error isa Sockets.DNSError && ex.error.code == EAI_AGAIN ? false : true
# Treat all DNS errors except `EAI_AGAIN`` as non-recoverable
# Ref: https://github.com/JuliaLang/julia/blob/ec8df3da3597d0acd503ff85ac84a5f8f73f625b/stdlib/Sockets/src/addrinfo.jl#L108-L112
function isrecoverable(ex::ConnectError)
if ex.error isa Sockets.DNSError
return (ex.error.code == Base.UV_EAI_AGAIN) ? true : false
else
return true
end
end
isrecoverable(ex::StatusError) = retryable(ex.status)

function _retry_check(s, ex, req, check)
Expand Down

0 comments on commit f4bd74b

Please sign in to comment.