Search code examples
ruby-on-railsrubyruby-on-rails-3rest-client

RestClient::RequestTimeout in controller#method ruby on rails


I am making the following rest get request:

 rest_user = JSON.parse(RestClient.get APP_CONFIG['api_url'] + "users/", :params => {:token => APP_CONFIG['token'], :full => 'true'} )["users"] 

I get the following error back after a minute:

 RestClient::RequestTimeout in controller#method


rbenv/versions/1.8.7-p374/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:184:in `transmit'
rbenv/versions/1.8.7-p374/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
rbenv/versions/1.8.7-p374/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
rbenv/versions/1.8.7-p374/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient.rb:68:in `get'

Now when I am tailing the logs of the actual service that is receiving this request, it is performing the requested request and completes it without any error.

But the consumer(the web applicaion) is throwing the request timeout error before the request has actually been fully completed.


Solution

  • It is absolutely normal. Your web app raises an error, because RestClient raises an error after 60 seconds if it has not received response yet.

    The app you are calling has no knowledge of that fact, so it continues processing as long as it is required to complete the request (it may take, 61 seconds, 70, ... ).

    url = APP_CONFIG['api_url'] + "users/"
    payload = {:token => APP_CONFIG['token'], :full => 'true'}
    RestClient::Execute.execute(method: :get, url: url, payload: payload, timeout: 120)