Netscape used to start a new thread (or maybe it was a subprocess?) to handle DNS lookups, because the API at the time (gethostbyname) was blocking. It's kind of amazing that we're 30 years on and this is still a problem.
Windows 8 and above also have their own asynchronous DNS API on NON-POSIX land.
[0] https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip...
To be precise, even on Linux getaddrinfo_a is not guaranteed to be present. It's a glibc extension. musl doesn't have it.
Calling a separate (non-cancellable) thread to perform the lookup sounds a like viable solution...