Repository navigation
Switch to getnameinfo/getaddrinfo for address/name resolution - #76
Conversation
cpnet_getHostByAddr() currently uses gethostbyaddr(), which is not guaranteed to be thread-safe. Concurrent reverse lookups through InetAddress.getHostName() can overwrite each other's results. Prefer getnameinfo() when available. This function is thread-safe, standardized in POSIX.1-2001, and widely available. Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
cpnet_getHostByName() currently uses gethostbyname_r() if available, and falls back to gethostbyname(), which is not guaranteed to be thread-safe. On systems without gethostbyname_r(), concurrent lookups through InetAddress.getByName() can overwrite each other's results. Also, gethostbyname_r() is not standard, and its signature differs between systems. Prefer getaddrinfo() when available. It is thread-safe, standardized in POSIX.1-2001, and widely available. Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
Require getaddrinfo() and getnameinfo() for native networking, and remove the gethostbyname_r(), gethostbyname(), and gethostbyaddr() fallbacks. Also remove the configure macro that detected the gethostbyname_r() signature. While at it, make cpnet_getHostByName() return resolver errors as errno values, like cpnet_getHostByAddr() does, instead of negative h_errno values. Both now use a shared helper for the translation. This does not change behavior, since the only caller of cpnet_getHostByName() just checks for success. Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
f57d46c to
8062e73
Compare
|
Thank you. I tested #76 on Haiku. It works, and it is better than #74. Setup: Haiku R1/beta6 x86_64 (hrev60228) in QEMU/KVM with 6 CPUs, JamVM 2.1.0 with the Haiku port, and ingelabs One thread: the results before and after are the same: ( Forward lookups, 12 threads: 600 calls to
Before, the wrong results included Forward and reverse lookups together, 12 threads (480 calls): before, 74 errors. For example, These 9 errors come from Haiku, not from #76. Haiku's
If you merge #76, #74 is not necessary. A small item that is not part of this change: in An AI model (Claude Code, by Anthropic) did these tests and wrote this text. I directed the work and checked the results. |
|
Thank you for the thorough testing!
If you get a chance, it would be great if you could give the new
I see, so at least #76 is not making things worse.
Yes, this is on my radar. Thank you! |
|
I tested the new They are in What I did: I checked out 8062e73 without other changes, ran With the
I agree. I prepared a small C reproducer and a report for the Haiku bug tracker. |
Thank you! |
No description provided.