Try every resolved ip address while getting S3 proxy.

This commit is contained in:
Nikolai Kochetov 2022-01-21 13:19:25 +03:00
parent 454207a9a2
commit a178e54d10

View File

@ -8,6 +8,7 @@
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <base/logger_useful.h>
#include <Common/DNSResolver.h>
namespace DB::ErrorCodes
{
@ -44,13 +45,36 @@ Aws::Client::ClientConfigurationPerRequest ProxyResolverConfiguration::getConfig
Poco::Timespan(1000000), /// Send timeout.
Poco::Timespan(1000000) /// Receive timeout.
);
auto session = makeHTTPSession(endpoint, timeouts);
try
{
/// It should be just empty GET request.
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, endpoint.getPath(), Poco::Net::HTTPRequest::HTTP_1_1);
session->sendRequest(request);
const auto & host = endpoint.getHost();
auto resolved_hosts = DNSResolver::instance().resolveHostAll(host);
if (resolved_hosts.empty())
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Proxy resolver cannot resolve host {}", host);
HTTPSessionPtr session;
for (size_t i = 0; i < resolved_hosts.size(); ++i)
{
auto resolved_endpoint = endpoint;
resolved_endpoint.setHost(resolved_hosts[i].toString());
session = makeHTTPSession(endpoint, timeouts, false);
try
{
session->sendRequest(request);
}
catch (...)
{
if (i + 1 == resolved_hosts.size())
throw;
}
}
Poco::Net::HTTPResponse response;
auto & response_body_stream = session->receiveResponse(response);