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(api): bound connect phase to 5.0s in two api/core/ outbound timeouts (#40807)

Harsh Kashyapca32e87683d2
diff --git a/api/core/helper/creators.py b/api/core/helper/creators.py
index 4ad61371512..154ff8dca68 100644
--- a/api/core/helper/creators.py
+++ b/api/core/helper/creators.py
@@ -17,10 +17,12 @@ logger = logging.getLogger(__name__)
creators_platform_api_url = URL(str(dify_config.CREATORS_PLATFORM_API_URL))
+_CREATORS_REQUEST_TIMEOUT: httpx.Timeout = httpx.Timeout(30.0, connect=5.0)
+
def upload_dsl(dsl_file_bytes: bytes, filename: str = "template.yaml") -> str:
url = str(creators_platform_api_url / "api/v1/templates/anonymous-upload")
- response = httpx.post(url, files={"file": (filename, dsl_file_bytes)}, timeout=30)
+ response = httpx.post(url, files={"file": (filename, dsl_file_bytes)}, timeout=_CREATORS_REQUEST_TIMEOUT)
response.raise_for_status()
data = response.json()
claim_code = data.get("data", {}).get("claim_code")
diff --git a/api/core/rag/extractor/watercrawl/client.py b/api/core/rag/extractor/watercrawl/client.py
index b069977de9b..bb93730dd4c 100644
--- a/api/core/rag/extractor/watercrawl/client.py
+++ b/api/core/rag/extractor/watercrawl/client.py
@@ -232,7 +232,7 @@ class WaterCrawlAPIClient(BaseAPIClient):
return event_data["data"]
def download_result(self, result_object: dict[str, Any]):
- response = httpx.get(result_object["result"], timeout=30)
+ response = httpx.get(result_object["result"], timeout=WATERCRAWL_REQUEST_TIMEOUT)
try:
response.raise_for_status()
result_object["result"] = response.json()
diff --git a/api/tests/unit_tests/core/helper/test_creators.py b/api/tests/unit_tests/core/helper/test_creators.py
index cac7ad35a71..bb0f4d8ec07 100644
--- a/api/tests/unit_tests/core/helper/test_creators.py
+++ b/api/tests/unit_tests/core/helper/test_creators.py
@@ -32,7 +32,17 @@ class TestUploadDSL:
mock_post.assert_called_once()
call_kwargs = mock_post.call_args
assert "anonymous-upload" in call_kwargs.args[0]
- assert call_kwargs.kwargs["timeout"] == 30
+ timeout = call_kwargs.kwargs["timeout"]
+ assert isinstance(timeout, httpx.Timeout)
+ assert timeout.connect == 5.0
+ assert timeout.read == 30.0
+
+ def test_creators_request_timeout_bounds_connect_phase(self):
+ """Module-level _CREATORS_REQUEST_TIMEOUT should bound the connect phase to 5.0s."""
+ from core.helper.creators import _CREATORS_REQUEST_TIMEOUT
+
+ assert _CREATORS_REQUEST_TIMEOUT.connect == 5.0
+ assert _CREATORS_REQUEST_TIMEOUT.read == 30.0
@patch("core.helper.creators.httpx.post")
def test_raises_on_missing_claim_code(self, mock_post):
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 bfb3754a7fd..701198e968e 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
@@ -4,6 +4,7 @@ import json
from typing import Any
from unittest.mock import MagicMock
+import httpx
import pytest
import core.rag.extractor.watercrawl.client as client_module
@@ -301,7 +302,10 @@ class TestWaterCrawlAPIClient:
result = client.download_result({"result": "https://example.com/result.json"})
assert result["result"] == {"markdown": "body"}
- assert captured["timeout"] is not None
+ timeout = captured["timeout"]
+ assert isinstance(timeout, httpx.Timeout)
+ assert timeout.connect == 5.0
+ assert timeout.read == 30.0
response.close.assert_called_once()