Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPClient::ReceiveTimeoutError in Ruby on Rails

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?

like image 937
yagmurdursun Avatar asked Apr 04 '12 14:04

yagmurdursun


2 Answers

Use for receive_timeout error;

client = HTTPClient.new
client.receive_timeout = 10000    # setting receivetimeout for HTTPClient!
like image 121
yagmurdursun Avatar answered Sep 25 '22 02:09

yagmurdursun


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
like image 42
allenhwkim Avatar answered Sep 25 '22 02:09

allenhwkim