Skip to content

Commit

Permalink
fix(http_proxy): actually perform DNS resolution when entry is stale (y…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorres authored Jun 4, 2024
1 parent 47fb45a commit 83145b0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ydb/library/actors/http/http_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class THttpProxy : public NActors::TActorBootstrapped<THttpProxy>, public THttpC
void Handle(TEvHttpProxy::TEvResolveHostRequest::TPtr event, const NActors::TActorContext& ctx) {
const TString& host(event->Get()->Host);
auto it = Hosts.find(host);
if (it == Hosts.end() || it->second.DeadlineTime > ctx.Now()) {
if (it == Hosts.end() || it->second.DeadlineTime < ctx.Now()) {
TString addressPart;
TIpPort portPart = 0;
CrackAddress(host, addressPart, portPart);
Expand Down Expand Up @@ -174,6 +174,22 @@ class THttpProxy : public NActors::TActorBootstrapped<THttpProxy>, public THttpC
it->second.DeadlineTime = ctx.Now() + HostsTimeToLive;
}
}
catch (const TNetworkResolutionError& e) {
if (it != Hosts.end()) {
ctx.Send(event->Sender, new TEvHttpProxy::TEvResolveHostResponse(it->first, it->second.Address));
return;
} else {
ctx.Send(event->Sender,
new TEvHttpProxy::TEvResolveHostResponse(
TStringBuilder()
<< "Resolution failed and no stale cached value has been found to fallback.\n"
<< "Resolution error: "
<< e.what()
)
);
return;
}
}
catch (const yexception& e) {
ctx.Send(event->Sender, new TEvHttpProxy::TEvResolveHostResponse(e.what()));
return;
Expand Down

0 comments on commit 83145b0

Please sign in to comment.