Get the latest tech news
RIP pthread_cancel
I posted about adding pthread_cancel use in curl about three weeks ago, we released this in curl 8.16.0 and it blew up right in our faces. Now, with #18540 we are ripping it out again. What happened? short recap pthreads define “Cancelation points”, a list of POSIX functions where a pthread may be cancelled. In addition, there is also a list of functions that may be cancelation points, among those getaddrinfo(). getaddrinfo() is exactly what we are interested in for libcurl. It blocks until it has resolved a name. That may hang for a long time and libcurl is unable to do anything else. Meh. So, we start a pthread and let that call getaddrinfo(). libcurl can do other things while that thread runs.
So, we added pthread_cancel() to interrupt a running getaddrinfo() and get rid of the pthread we no longer needed. After releasing curl 8.16.0 we got an issue reported in#18532 that cancelled pthreads leaked memory. Digging into the glibc source shows that there is this thing called/etc/gai.conf which defines how getaddrinfo() should sort returned answers.
Or read this on Hacker News