I'm having trouble with Timeouts which do not work reliably under JRuby (Linux). More specifically, if I send a HEAD Request to a remote server and this server is busy (does not respond), the configured timeout does not fire and my application stalls for a long time. I tried both, setting read_timeout
and using the timeout()
function but none worked reliably:
Timeout::timeout(5) do
Net::HTTP.start(uri.host, uri.port) do |http|
http.read_timeout = 5
http.request_head(uri.request_uri)
end
end
For Ruby this problem is extensively document at the SystemTimer page. However, the proposed SystemTimer gem cannot be used with JRuby.
Does anyone have an idea how to get reliable timeouts for HTTP requests in JRuby?
PS: This is JRuby 1.1.6 / 32-bit Linux / Sun Java 1.6