Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(watercrawl): don't disable request timeouts with timeout=None (#37685)

Yufeng He265dc54c5193
diff --git a/api/core/rag/extractor/watercrawl/client.py b/api/core/rag/extractor/watercrawl/client.py
index b37bd38ec3e..51dd26b1ad0 100644
--- a/api/core/rag/extractor/watercrawl/client.py
+++ b/api/core/rag/extractor/watercrawl/client.py
@@ -14,6 +14,12 @@ from core.rag.extractor.watercrawl.exceptions import (
WATERCRAWL_REQUEST_TIMEOUT: httpx.Timeout = httpx.Timeout(30.0, connect=5.0)
+# The crawl-status stream is a long-lived SSE connection that can stay open for
+# the whole duration of a crawl, so it keeps an unbounded read while still
+# capping the initial connection. Regular requests use WATERCRAWL_REQUEST_TIMEOUT
+# so a stalled endpoint can't hang a worker forever.
+_STREAM_TIMEOUT = httpx.Timeout(None, connect=10.0)
+
class SpiderOptions(TypedDict):
max_depth: int
@@ -50,6 +56,8 @@ class BaseAPIClient:
"User-Agent": "WaterCrawl-Plugin",
"Accept-Language": "en-US",
}
+ # Regular requests use WATERCRAWL_REQUEST_TIMEOUT; the long-lived
+ # crawl-status stream overrides it with _STREAM_TIMEOUT in _request.
return httpx.Client(headers=headers, timeout=WATERCRAWL_REQUEST_TIMEOUT)
def _request(
@@ -63,7 +71,7 @@ class BaseAPIClient:
stream = kwargs.pop("stream", False)
url = urljoin(self.base_url, endpoint)
if stream:
- request = self.session.build_request(method, url, params=query_params, json=data)
+ request = self.session.build_request(method, url, params=query_params, json=data, timeout=_STREAM_TIMEOUT)
return self.session.send(request, stream=True, **kwargs)
return self.session.request(method, url, params=query_params, json=data, **kwargs)
diff --git a/api/tests/unit_tests/core/rag/extractor/watercrawl/test_watercrawl.py b/api/tests/unit_tests/core/rag/extractor/watercrawl/test_watercrawl.py
index 05985d30985..673f1e41c5d 100644
--- a/api/tests/unit_tests/core/rag/extractor/watercrawl/test_watercrawl.py
+++ b/api/tests/unit_tests/core/rag/extractor/watercrawl/test_watercrawl.py
@@ -77,6 +77,15 @@ class TestBaseAPIClient:
assert captured["timeout"].connect is not None
assert captured["timeout"].read is not None
+ def test_init_session_uses_bounded_default_timeout(self):
+ # Regression: the session was built with timeout=None, which disables
+ # httpx's timeouts entirely, so a stalled WaterCrawl endpoint would hang
+ # the calling worker forever. Regular requests must keep a bounded timeout.
+ session = BaseAPIClient(api_key="k", base_url="https://watercrawl.dev").session
+
+ assert session._timeout.connect is not None
+ assert session._timeout.read is not None
+
def test_request_stream_and_non_stream_paths(self, monkeypatch: pytest.MonkeyPatch):
class FakeSession:
def __init__(self):
@@ -88,8 +97,8 @@ class TestBaseAPIClient:
self.request_calls.append((method, url, params, json, kwargs))
return "non-stream-response"
- def build_request(self, method, url, params=None, json=None):
- req = (method, url, params, json)
+ def build_request(self, method, url, params=None, json=None, timeout=None):
+ req = (method, url, params, json, timeout)
self.build_calls.append(req)
return req
@@ -108,6 +117,11 @@ class TestBaseAPIClient:
assert client._request("GET", "/v1/items", stream=True) == "stream-response"
assert fake_session.build_calls
assert fake_session.send_calls[0][1] is True
+ # the streaming request keeps an unbounded read (the SSE status stream can
+ # stay open for the whole crawl) while still capping the connection
+ stream_timeout = fake_session.build_calls[0][4]
+ assert stream_timeout.read is None
+ assert stream_timeout.connect is not None
def test_http_method_helpers_delegate_to_request(self, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(BaseAPIClient, "init_session", lambda self: MagicMock())