I'm trying to perform a local request with httr2
. I don't seem to be able to keep the request waiting for more than 10 minutes. I appreciate this is a very long time, but in my case, it is occasionally expected.
Even if I set a very high timeout of many hours with:
req |>
httr2::req_timeout(seconds = 333333) |>
httr2::req_perform()
I still get the following error after 10 minutes:
Error in `httr2::req_perform()`:
! Failed to perform HTTP request.
Caused by error in `curl::curl_fetch_memory()`:
! Timeout was reached [localhost]:
Operation too slow. Less than 1 bytes/sec transferred the last 600 seconds
Run `rlang::last_trace()` to see where the error occurred.
If I print the request object, I see it records the lengthy timeout:
Options:
* timeout_ms : 333333000
* connecttimeout: 0
This is with the most recent version available on CRAN for key packages, in particular httr2
version 1.2.1, and rcurl
version 1.98-1.17 (latest R 4.5.1 on Fedora Linux).
Any hint for increasing this timeout above 600 seconds or further troubleshooting is warmly welcome.
im sorry for the previous answer. i hope this time i can make it easier.
This code sets the overall timeout and, critically, disables the low-speed timeout by setting low_speed_limit = 0. This prevents libcurl from prematurely aborting the connection.
low_speed_limit: Most important. Minimum data transfer rate. 0 disables the low-speed timeout.
low_speed_time: How long the transfer must be slow (if low_speed_limit > 0).
library(httr2)
# 1. Configure libcurl options for the specific request
req <- request("http://localhost:8000/your-long-running-endpoint") # Replace with your actual endpoint
req <- req |>
req_options(
timeout_ms = 333333000,
low_speed_limit = 0, #Set to 0 to disable
low_speed_time = 3600 #seconds
) |>
req_perform()
print(req) #result
# 2. (Less likely to help, but check R's global timeout option)
options("timeout") # See current setting
# Set a very long timeout (use with caution!) - If needed
options(timeout = 333333)
# Restore to previous settings after making the request:
#options(timeout = <original_timeout_value>) #Replace with your initial setting