actonlang / acton

The Acton Programming Language
https://www.acton-lang.org/
BSD 3-Clause "New" or "Revised" License
76 stars 7 forks source link

Prefer getaddrinfo over gethostbyname #648

Open plajjan opened 2 years ago

plajjan commented 2 years ago

I don't think gethostbyname is thread safe. For the DB server this is currently not a problem but RTS is threaded so the client_api needs to be thread safe and thus I think we should avoid gethostbyname in preference of its more modern sibling getaddrinfo!

aagapi commented 2 years ago

In the current uses and the current version of the client DB API, as called by the RTS, gethostbyname() not being thread safe is not actually a problem because it is either called in the beginning from the main thread as the RTS gets a handler to the DB client (which it then shares with all the actor threads), either subsequently from the comm thread when new servers are learned of by gossip. The other problem with gethostbyname() is that it is not re-entrant, which we handle by copying address info from its output static buffer to our own memory space after each call. That being said, it is definitely a good idea to move from gethostbyname() to getaddrinfo() (which is both re-entrant and thread safe), both because gethostbyname() is deprecated by getaddrinfo(), and to future-proof the system to cases where the call pattern might change in the future to require thread safety (e.g. if we make the incoming comm processing pipeline that handles gossip notifications multithreaded).