Skip to content

Conversation

@schell244
Copy link
Contributor

🍰 Pullrequest

Adds configurable DNS resolution timeout to prevent the realm server from hanging when DNS servers are unreachable or slow to respond.

Scenario Before After
DNS server unreachable Server hangs indefinitely Returns after timeout, realm temporarily skipped
DNS server slow (>5s) Waits for OS timeout (30-120s) Returns after configured timeout
Repeated DNS failures Unlimited blocking threads Limited to 10 concurrent threads
DNS recovers N/A Realm automatically returns on next update cycle

Proof

  • None

Issues

  • None

How2Test

  • None

Todo / Checklist

  • None

addrinfo* dnsResult = nullptr;
if (::getaddrinfo(domainName.c_str(), nullptr, &hints, &dnsResult) != 0)
// Worker thread that performs the DNS resolution
std::thread resolverThread([state, domainName, type]()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is good practice. The other solution would be to use our IoContext and then ::GetAddrInfoExW

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw we dont use std::thread to spawn threads. Prefer to use IO::Multithreading::CreateThread

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! Went with the lazy IO::Multithreading::CreateThread solution for now - need to look into ::GetAddrInfoExW, but this would mean platform specific implemenations, correct?

Copy link
Collaborator

@0blu 0blu Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, its OS specific. In linux/macos it would be getaddrinfo_a.
Although your current solution works, it feels wrong to create a heavy std::thread for just a simple IO task and letting a timeout run in the main thread.

And what happens if a DNS requests gets stuck forever and never resolves?
MAX_PENDING_DNS_RESOLUTIONS would be reached and is denying further requests that might work.

With GetAddrInfoExW/getaddrinfo_a you don't need to spawn a new thread and correctly cancel timed'out requests.

MANGOS_ASSERT(type == IpAddress::Type::IPv4); // TODO: this function is only tested with IPv4. `inet_ntop` will fail
// Limit concurrent pending DNS resolutions to prevent thread accumulation on DNS failures
std::atomic<int> g_pendingDnsResolutions{0};
constexpr int MAX_PENDING_DNS_RESOLUTIONS = 10;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

east const 🙃

@0blu
Copy link
Collaborator

0blu commented Jan 10, 2026

Have you experienced a blocking DNS requests on your system or what's the reason for this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants