Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set timeouts for HTTP requests #613

Open
TomAugspurger opened this issue Feb 4, 2025 · 1 comment
Open

Set timeouts for HTTP requests #613

TomAugspurger opened this issue Feb 4, 2025 · 1 comment

Comments

@TomAugspurger
Copy link

xref #603 (comment)

Investigate whether it's possible for the current remote IO implementation to hang indefinitely. https://curl.se/libcurl/c/CURLOPT_TIMEOUT.html describes the option we probably want. We can add that as an option in libcurl.cpp next to the other CURLOPTs.

We'd need to figure out a good default value for this parameter and a way to configure it.

There's an interaction with #603: timeout errors raised by libcurl is one of the non-completed HTTP request / response errors that should be retried automatically (along with things like closed sockets).

@TomAugspurger
Copy link
Author

A quick test on top of #603

diff --git a/cpp/src/shim/libcurl.cpp b/cpp/src/shim/libcurl.cpp
index 825c38a..d2912d1 100644
--- a/cpp/src/shim/libcurl.cpp
+++ b/cpp/src/shim/libcurl.cpp
@@ -110,6 +110,7 @@ CurlHandle::CurlHandle(LibCurl::UniqueHandlePtr handle,
 
   // Make curl_easy_perform() fail when receiving HTTP code errors.
   setopt(CURLOPT_FAILONERROR, 1L);
+  setopt(CURLOPT_TIMEOUT, 5L);
 }
 
 CurlHandle::~CurlHandle() noexcept { LibCurl::instance().retain_handle(std::move(_handle)); }
diff --git a/python/kvikio/tests/test_http_io.py b/python/kvikio/tests/test_http_io.py
index b084f81..2998baf 100644
--- a/python/kvikio/tests/test_http_io.py
+++ b/python/kvikio/tests/test_http_io.py
@@ -3,6 +3,7 @@
 
 
 import http
+import time
 from http.server import SimpleHTTPRequestHandler
 from typing import Literal
 
@@ -68,6 +69,7 @@ class HTTP500Handler(SimpleHTTPRequestHandler):
                 return super().do_HEAD()
 
     def do_GET(self) -> None:
+        time.sleep(10)
         return self._do_with_error_count("GET")
 
     def do_HEAD(self) -> None:

The HTTP server sleeps for 10 seconds before responding to GET requests. kvikio is configured to time out after 5s.

The first GET request time out, and isn't retried:

127.0.0.1 - - [04/Feb/2025 14:40:50] "HEAD /a HTTP/1.1" 200 -
FAILED

=============================================================================================================================================== FAILURES ===============================================================================================================================================
_____________________________________________________________________________________________________________________________________ test_retry_http_500_ok[cupy] _____________________________________________________________________________________________________________________________________
python/kvikio/tests/test_http_io.py:178: in test_retry_http_500_ok
    f.read(b)
python/kvikio/kvikio/remote_file.py:182: in read
    return self.pread(buf, size, file_offset).get()
python/kvikio/kvikio/cufile.py:54: in get
    return self._handle.get()
future.pyx:33: in kvikio._lib.future.IOFuture.get
    ???
E   RuntimeError: curl_easy_perform() error near /home/coder/kvikio/cpp/src/remote_handle.cpp:353(Operation timed out after 5002 milliseconds with 0 bytes received)
======================================================================================================================================= short test summary info ========================================================================================================================================
FAILED python/kvikio/tests/test_http_io.py::test_retry_http_500_ok[cupy] - RuntimeError: curl_easy_perform() error near /home/coder/kvikio/cpp/src/remote_handle.cpp:353(Operation timed out after 5002 milliseconds with 0 bytes received)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant