SDL_net icon indicating copy to clipboard operation
SDL_net copied to clipboard

SDLNet_WaitUntilResolved is broken when using timeouts

Open JoelLinn opened this issue 9 months ago • 0 comments

SDL_net 78dc78694f17317b08ec788d4812e74850b4acff SDL d95f5bad2459608816cbf24f14dcab618a4a9ab7 prerelease-3.1.2

Hi,

when setting a timeout, SDLNet_WaitUntilResolved has broken behaviour. This can be reproduced using one of the examples:

diff --git a/examples/resolve-hostnames.c b/examples/resolve-hostnames.c
index ac28e7b..0efae0d 100644
--- a/examples/resolve-hostnames.c
+++ b/examples/resolve-hostnames.c
@@ -25,7 +25,7 @@ int main(int argc, char **argv)
     }
 
     for (int i = 1; i < argc; i++) {
-        SDLNet_WaitUntilResolved(addrs[i], -1);
+        SDLNet_WaitUntilResolved(addrs[i], 1000);
 
         if (SDLNet_GetAddressStatus(addrs[i]) == -1) {
             SDL_Log("%s: [FAILED TO RESOLVE: %s]", argv[i], SDL_GetError());
> ./resolve-hostnames 8.8.8.8

Issues:

  • The hostname(s) will not resolve: INFO: 8.8.8.8: (null) but the return code indicates success (except when adding SDL_Delay(1000); before the call to SDLNet_WaitUntilResolved, indicating a race)
  • The application will hang on SDLNet_Quit(), waiting for the resolve threads:
(gdb) bt 10
#0  0x00007ffff7aa5ebe in ?? () from /usr/lib/libc.so.6
#1  0x00007ffff7aab0e3 in ?? () from /usr/lib/libc.so.6
#2  0x00007ffff7ea2019 in SDL_SYS_WaitThread () from /home/[...]/SDL/cmake-install/lib/libSDL3.so.0
#3  0x00007ffff7d0ba98 in SDL_WaitThread_REAL () from /home/[...]/SDL/cmake-install/lib/libSDL3.so.0
#4  0x00007ffff7c6594c in SDL_WaitThread () from /home/[...]/SDL/cmake-install/lib/libSDL3.so.0
#5  0x00007ffff7fb90e1 in SDLNet_Quit () at /home/[...]/SDL_net/src/SDL_net.c:442
#6  0x000055555555537b in main (argc=2, argv=0x7fffffffe428) at /home/[...]/SDL_net/examples/resolve-hostnames.c:39

JoelLinn avatar May 03 '24 09:05 JoelLinn