summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorRubidium <rubidium@openttd.org>2021-04-11 11:32:31 +0200
committerPatric Stout <github@truebrain.nl>2021-04-12 21:10:21 +0200
commitd2fe8c2842c7930d5fca4f10bad276b706393946 (patch)
treeb473ce7a3543646e53991f0dc16052fdcf0c556e /src/network
parent7597740bff711d78e3f005bdfad214154281559a (diff)
downloadopenttd-d2fe8c2842c7930d5fca4f10bad276b706393946.tar.xz
Change: warn the user about the resolving of an address being extra very slow
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/address.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp
index a45bd4914..8c6909438 100644
--- a/src/network/core/address.cpp
+++ b/src/network/core/address.cpp
@@ -239,7 +239,18 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
strecpy(this->hostname, fam == AF_INET ? "0.0.0.0" : "::", lastof(this->hostname));
}
+ static bool _resolve_timeout_error_message_shown = false;
+ auto start = std::chrono::steady_clock::now();
int e = getaddrinfo(StrEmpty(this->hostname) ? nullptr : this->hostname, port_name, &hints, &ai);
+ auto end = std::chrono::steady_clock::now();
+ std::chrono::seconds duration = std::chrono::duration_cast<std::chrono::seconds>(end - start);
+ if (!_resolve_timeout_error_message_shown && duration >= std::chrono::seconds(5)) {
+ DEBUG(net, 0, "getaddrinfo for hostname \"%s\", port %s, address family %s and socket type %s took %i seconds",
+ this->hostname, port_name, AddressFamilyAsString(family), SocketTypeAsString(socktype), (int)duration.count());
+ DEBUG(net, 0, " this is likely an issue in the DNS name resolver's configuration causing it to time out");
+ _resolve_timeout_error_message_shown = true;
+ }
+
if (reset_hostname) strecpy(this->hostname, "", lastof(this->hostname));