This project is archived and is in readonly mode.
ActiveResource timeout doesn't set open_timeout on underlying Net:HTTP object
-
Michael Koziarski
- Tag changed from activeresource to activeresource, bugmash
-
Josh Nichols
+1 on this. read_timeout helps when the connection is open and is slow to serve up its goods, but does nothing about a slow response when opening in the first place.
-
pjammer
I can't create a patch, however i dug into this and here is what i've found.
We need to simply add the open_timeout to accept the timeout variable, so no additional functionality/arg's need to be changed in a person's app code. If they used timeout before, we simply take that same variable and apply it to Net::HTTP#opne_timeout, which is the variable you want to use if there is NO connection to a server. it appears the read_timeout variable is applied if you get a response but then nothing comes back, which as you can tell, is different then from being shut out of the server altogether.
Here is the code.
Line 139ish... http.open_timeout = @timeout ||= 60 #default to 60 seconds. currently default is never.I've used the rdocs for Net::HTTP to verify the open_timeout method here:
open_timeout [RW] Seconds to wait until connection is opened. If the HTTP object cannot open a connection in this many seconds, it raises a TimeoutError exception.
Net::HTTP open_timeout doesn't have a default value however, it's set to nil == forever, so we set it to 60 seconds, to match the read_timeout variable's default in Net::HTTP.
-
Josh Nichols
Attached a patch to deal with this.
There's a couple of complications. Mainly, the 'http' method is what is building the Net::HTTP object. This would be fine, except that that lib/active_resource/http_mock overrides this entirely to use itself (ActiveResource::HttpMock). Considering this is kind of a public API, I didn't want to change the 'http' method, so instead, I created a 'build_http' method which handles the actual construction. I made a few tests which test that things happen sanely during build_http, including setting open_timeout.
I think some additional tests could be added for building the http object, but this should be enough for this particular issue.
-
Repository
- State changed from new to resolved
(from [a0caad5255ed120192755fce10960a38b53c056d]) Setting connection timeout also affects Net::HTTP open_timeout.
[#2947 ActiveResource timeout doesn't set open_timeout on underlying Net:HTTP object state:resolved] http://github.com/rails/rails/commit/a0caad5255ed120192755fce10960a...
-
Repository
(from [83cc7de2a47df199348cc47d2794a3f30ad4f4fb]) Setting connection timeout also affects Net::HTTP open_timeout.
[#2947 ActiveResource timeout doesn't set open_timeout on underlying Net:HTTP object state:resolved] http://github.com/rails/rails/commit/83cc7de2a47df199348cc47d2794a3...
-
Jeremy Kemper
- Tag changed from activeresource, bugmash to activeresource
Josh, rebased your patch against the proxy change and updated the test to not need a mock.
