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?
Use for receive_timeout error;
client = HTTPClient.new
client.receive_timeout = 10000 # setting receivetimeout for HTTPClient!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With