nikeshn commited on
Commit
adcc2dd
·
verified ·
1 Parent(s): f8c042e

Update src/services/http_client.py

Browse files
Files changed (1) hide show
  1. src/services/http_client.py +17 -3
src/services/http_client.py CHANGED
@@ -30,10 +30,24 @@ def make_transport(retries: int = 2) -> httpx.AsyncHTTPTransport:
30
  return httpx.AsyncHTTPTransport(retries=retries)
31
 
32
 
33
- def make_client(timeout: float = 8.0, retries: int = 2) -> httpx.AsyncClient:
34
- """AsyncClient pinned to IPv4 with transport retries."""
 
 
 
 
 
 
 
 
35
  return httpx.AsyncClient(
36
- timeout=timeout,
 
 
 
 
 
 
37
  transport=make_transport(retries=retries),
38
  follow_redirects=True,
39
  )
 
30
  return httpx.AsyncHTTPTransport(retries=retries)
31
 
32
 
33
+ def make_client(timeout: float = 25.0, retries: int = 2) -> httpx.AsyncClient:
34
+ """AsyncClient pinned to IPv4 with transport retries and a generous
35
+ connect budget.
36
+
37
+ Observed behaviour on Hugging Face Spaces: the TCP/TLS handshake to the
38
+ Cloudflare edge can take well over five seconds, so short connect timeouts
39
+ fail while longer ones succeed against the same host. Connect gets the full
40
+ budget; reads are capped separately so a hung response cannot stall a
41
+ request handler indefinitely.
42
+ """
43
  return httpx.AsyncClient(
44
+ timeout=httpx.Timeout(
45
+ timeout,
46
+ connect=max(timeout, 20.0),
47
+ read=timeout,
48
+ write=timeout,
49
+ pool=timeout,
50
+ ),
51
  transport=make_transport(retries=retries),
52
  follow_redirects=True,
53
  )