request: in the event of failure, try other IPs (#6761)#6813
request: in the event of failure, try other IPs (#6761)#6813Gargron merged 6 commits intomastodon:masterfrom
Conversation
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.
|
The CI build is failing on:
This is due to the test case being tied to IPSocket.getaddress. Also there ought to be a test case to test for the round-robin working as expected. |
app/lib/request.rb
Outdated
| super address, *args | ||
| outer_e = nil | ||
| Addrinfo.foreach(host, nil, nil, :SOCK_STREAM) do |address| | ||
| raise Mastodon::HostValidationError if PrivateAddressCheck.private_address? IPAddr.new(address.ip_address) |
There was a problem hiding this comment.
Please move this line in the begin...rescue section. Such a case that one of addresses are invalid but the others are valid should have been tolerated in releases prior to v2.3.0.
|
Currently stalled on: My Ruby/RSpec experience is lacking, so I'm going to take a break for the night. |
spec/lib/request_spec.rb
Outdated
| end | ||
|
|
||
| it 'executes a HTTP request when the first address is private' do | ||
| allow(Addrinfo).to receive(:foreach).with('example.com', nil, nil, :SOCK_STREAM).and_return([ |
There was a problem hiding this comment.
| @@ -94,9 +94,16 @@ def http_client | |||
| class Socket < TCPSocket | |||
There was a problem hiding this comment.
@akihikodaki Isn't there different classes for Socket and SSLSocket?
There was a problem hiding this comment.
SSLSocket uses TCPSocket, so patching only TCPSocket is enough.
There was a problem hiding this comment.
But this doesn't patch TCPSocket, only our own Socket class, no?
There was a problem hiding this comment.
SSLSocket takes a TCPSocket instance as an argument when initializes, and HTTP gem uses our patched TCPSocket to create an instance for the argument. That's how it works.
akihikodaki
left a comment
There was a problem hiding this comment.
I fixed the spec, and now it is ready to merge. I hope it will be in v2.3.2.
…odon#6813) * request: in the event of failure, try other IPs (mastodon#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
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.