HTTPClient::ReceiveTimeoutError in Ruby on Rails
httpclient, ruby-on-rails, timeout
Solution
I guess your http connection or remote connection is not stable. Whenever i have that situation, i use timeout and retry for few times. The following code will execute your code for 10 seconds, and if not finished it will timeout and retry. If retry fails for many times, it will fail eventually.
def timeout_and_retry
retries = 0
begin
Timeout::timeout(10) { yield }
rescue Timeout::Error
raise if (self.retries += 1) > 3
retry
end
end
timeout_and_retry do
# http client get code goes here
end
Problem
Hi I am using HTTPClient gem and I have a problem; I use it for user signup. While running user name and password are inserted to my database but it waits long and return to me ``` HTTP Client::ReceiveTimeout Error in User Controller#signup execution expired. ``` how can I fix my problem?