4

I am running several scripts to post and retrieve data using the httr package. Occasionally, one of the jobs will just stall and never complete. This causes problems when other scripts assume that this script has completed. The stalling is due to some error on the server on the other end.

Is it, therefore, possible to specify a maximal waiting time for a POST/GET request?

I have looked at the documentation and found the httr::timeout() function. It passes arguments to curl::setopt(), and supposedly answers my question.

However, when I look at the curl option for timeout I find:

> curl::curl_options("^timeout$")
> timeout
> 13

And this is not what I am experiencing in practice? What Am I missing?

symbolrush
  • 7,123
  • 1
  • 39
  • 67
Jagge
  • 938
  • 4
  • 21

1 Answers1

4

One option is to include the timeout specification directly in your GET request:

library(httr)
GET("http://httpbin.org/delay/3", timeout(1))

This returns a timeout error as follows:

Error in curl::curl_fetch_memory(url, handle = handle) : Timeout was reached: [httpbin.org] Operation timed out after 1000 milliseconds with 0 bytes received

symbolrush
  • 7,123
  • 1
  • 39
  • 67
  • is it really that simple? From what i could figure out, the default value is 13 (seconds?), but I have a job that is still running, but has been stalling for the last +12 hours. – Jagge Oct 15 '20 at 08:02