Bug 14001 - getaddrinfo sometimes slow in multithreaded programs
Summary: getaddrinfo sometimes slow in multithreaded programs
Status: RESOLVED WORKSFORME
Alias: None
Product: glibc
Classification: Unclassified
Component: network (show other bugs)
Version: 2.15
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-20 08:51 UTC by Winfried Peltz
Modified: 2014-06-25 11:14 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
test program (295 bytes, text/x-csrc)
2012-04-20 08:51 UTC, Winfried Peltz
Details
new test program (297 bytes, text/x-csrc)
2012-04-20 10:53 UTC, Winfried Peltz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Winfried Peltz 2012-04-20 08:51:46 UTC
Created attachment 6352 [details]
test program

If two or more threads invoke getaddrinfo for the same node at (about) the same time, the program hangs for 5 seconds (Fedora 17 x64_64, glibc 2.15) or for an integral multiple of 5 seconds (Fedora 16 x64_64, glibc 2.14) before delivering the correct result.

I have attached a short test program. You can try something like this:

time ./getaddrinfo_test www.amazon.com
(Amazon is one of the "slowest" hosts under Fedora 16. It often hangs for 20 or 25 seconds.)

If you specify a second argument, the second thread invokes getaddrinfo with that second argument as "node". If the two nodes differ, the program never hangs.

The program also doesn't hang if the node is "localhost". Under Fedora 17, it doesn't hang if it is executed for a second time with the same node shortly after the first execution. But under Fedora 16 it hangs even in this case.

One program that is affected by this bug is Privoxy. It starts a new thread for each request, and if someone opens a web page the browser sends many requests to the proxy for all the elements on the web page which in most cases go to the same server. It doesn't cache the result of getaddrinfo. (Should it? I don't think so.)
Comment 1 Winfried Peltz 2012-04-20 10:53:51 UTC
Created attachment 6353 [details]
new test program

Sorry, there was a bug in my first test program. It didn't work correctly with 2 arguments. But this changes nothing I wrote above.
Comment 2 Ondrej Bilka 2013-10-13 07:47:05 UTC
I cannot replicate this issue on 2.17. Attached program has same latency as without multiple threads.
Comment 3 Ondrej Bilka 2013-11-06 11:22:57 UTC
I cannot duplicate this issue.