Steps to reproduce:
Multiplayer
.Search internet
.There's a pretty decent chance (about one in three in my tests) that OpenTTD will deadlock.
Applying this workaround solves this issue but is obviously not correct because getaddrinfo
would still not be thread-safe if the user program calls one of the underlying function in a separate threads (e.g. gethostbyname
or getservbyname
):
diff --git a/Userland/Libraries/LibC/netdb.cpp b/Userland/Libraries/LibC/netdb.cpp
index fad14c2b4..795045dfc 100644
--- a/Userland/Libraries/LibC/netdb.cpp
+++ b/Userland/Libraries/LibC/netdb.cpp
@@ -9,6 +9,7 @@
#include <AK/ScopeGuard.h>
#include <AK/String.h>
#include <Kernel/Net/IPv4.h>
+#include <LibC/bits/pthread_integration.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
@@ -643,8 +644,15 @@ static bool fill_getproto_buffers(const char* line, ssize_t read)
return true;
}
+static pthread_mutex_t gai_mutex = __PTHREAD_MUTEX_INITIALIZER;
+
int getaddrinfo(const char* __restrict node, const char* __restrict service, const struct addrinfo* __restrict hints, struct addrinfo** __restrict res)
{
+ __pthread_mutex_lock(&gai_mutex);
+ ScopeGuard guard = [] {
+ __pthread_mutex_unlock(&gai_mutex);
+ };
+
dbgln("getaddrinfo: node={}, service={}, hints->ai_family={}", (const char*)node, (const char*)service, hints ? hints->ai_family : 0);
*res = nullptr;
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too