➤ libcurl 因記憶體洩漏問題,放棄利用 pthread_cancel() 中斷 DNS 解析的策略
✤ https://eissing.org/icing/posts/rip_pthread_cancel/
libcurl 在 8.16.0 版本中引入了使用 pthread_cancel() 來中斷長時間執行的 getaddrinfo() 呼叫,以避免封鎖主執行緒。然而,此機制導致了記憶體洩漏問題,因為在處理 DNS 解析時,getaddrinfo() 讀取 /etc/gai.conf 的過程可能成為取消點,進而洩漏已分配的記憶體。儘管 glibc 的設計未能完全防止此類洩漏,libcurl 團隊仍決定捨棄 pthread_cancel(),改為接受 getaddrinfo() 可能造成的延遲,並建議使用者考慮使用 c-ares 來進行非同步 DNS 解析。
+ 這真是個令人頭
#網路 #DNS #libcurl #多執行緒 #pthread_cancel
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.