httpclient icon indicating copy to clipboard operation
httpclient copied to clipboard

thread safety - Address already in use - connect(2)

Open dnajd opened this issue 13 years ago • 1 comments

I'm making http requests to a few rest resources using httpclient. I read it's thread safe and was excited, but I keep getting this error:

Address already in use - connect(2) (http://api.mysite.com:80)|backtrace=["/vendor/ruby/1.9.1/gems/httpclient-2.3.0.1/lib/httpclient/session.rb:802:in initialize'", "/vendor/ruby/1.9.1/gems/httpclient-2.3.0.1/lib/httpclient/session.rb:802:innew'", "vendor/ruby/1.9.1/gems/httpclient-2.3.0.1/lib/httpclient/session.rb:802:in create_socket'", "/vendor/ruby/1.9.1/gems/httpclient-2.3.0.1/lib/httpclient/session.rb:751:inblock in connect'",

Each thread is making calls to 3 different rest resources. I'm running it under ruby 1.9.3p286 on mac osx.

Thanks,

Don

dnajd avatar Nov 28 '12 00:11 dnajd

I have no idea why TCPSocket.new('api.mysite.com', 80) can cause EADDRINUSE... https://github.com/nahi/httpclient/blob/e591eb75c5023ae666094d565f8f61f470be27d9/lib/httpclient/session.rb#L802

MT usage should be creating a single HTTPClient instance and all threads use the instance to access 3 different rest resources. Connections should be properly reused...

nahi avatar Nov 03 '14 12:11 nahi