diff options
author | Rey Tucker <git@reytucker.us> | 2018-03-20 04:06:08 -0400 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2018-03-20 09:06:08 +0100 |
commit | 36b57037961383466b7f5c20b39ee68cd9f202a0 (patch) | |
tree | 3b5f496101f3fdb59f19a2a764e99a826a9d96ef /app | |
parent | ff6b8a6443c2c97d185927053bdc8816e0e03434 (diff) |
request: in the event of failure, try other IPs (#6761) (#6813)
* request: in the event of failure, try other IPs (#6761) In the case where a name has multiple A/AAAA records, we should try subsequent records instead of immediately failing when we have a failure on the first IP address. This significantly improves delivery success when there are network connectivity problems affecting only IPv4 or IPv6. * fix method call style * request_spec: adjust test case to use Addrinfo * request: Request/open: move private addr check to within begin/rescue * request_spec: add case to test failover, fix exception check * Double Addrinfo.foreach so that it correctly yields instances
Diffstat (limited to 'app')
-rw-r--r-- | app/lib/request.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/app/lib/request.rb b/app/lib/request.rb index 5776b3d78..298fb9528 100644 --- a/app/lib/request.rb +++ b/app/lib/request.rb @@ -94,9 +94,16 @@ class Request class Socket < TCPSocket class << self def open(host, *args) - address = IPSocket.getaddress(host) - raise Mastodon::HostValidationError if PrivateAddressCheck.private_address? IPAddr.new(address) - super address, *args + outer_e = nil + Addrinfo.foreach(host, nil, nil, :SOCK_STREAM) do |address| + begin + raise Mastodon::HostValidationError if PrivateAddressCheck.private_address? IPAddr.new(address.ip_address) + return super address.ip_address, *args + rescue => e + outer_e = e + end + end + raise outer_e if outer_e end alias new open |