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: correct http timeout configs‘ default values and ignorance by HttpRequestNode (#7762)

Bowen Liang0c2a62f8479d
diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py
index f2efa52de3e..303bce2aa50 100644
--- a/api/configs/feature/__init__.py
+++ b/api/configs/feature/__init__.py
@@ -1,4 +1,4 @@
-from typing import Optional
+from typing import Annotated, Optional
from pydantic import AliasChoices, Field, HttpUrl, NegativeInt, NonNegativeInt, PositiveInt, computed_field
from pydantic_settings import BaseSettings
@@ -217,20 +217,17 @@ class HttpConfig(BaseSettings):
def WEB_API_CORS_ALLOW_ORIGINS(self) -> list[str]:
return self.inner_WEB_API_CORS_ALLOW_ORIGINS.split(",")
- HTTP_REQUEST_MAX_CONNECT_TIMEOUT: NonNegativeInt = Field(
- description="",
- default=300,
- )
+ HTTP_REQUEST_MAX_CONNECT_TIMEOUT: Annotated[
+ PositiveInt, Field(ge=10, description="connect timeout in seconds for HTTP request")
+ ] = 10
- HTTP_REQUEST_MAX_READ_TIMEOUT: NonNegativeInt = Field(
- description="",
- default=600,
- )
+ HTTP_REQUEST_MAX_READ_TIMEOUT: Annotated[
+ PositiveInt, Field(ge=60, description="read timeout in seconds for HTTP request")
+ ] = 60
- HTTP_REQUEST_MAX_WRITE_TIMEOUT: NonNegativeInt = Field(
- description="",
- default=600,
- )
+ HTTP_REQUEST_MAX_WRITE_TIMEOUT: Annotated[
+ PositiveInt, Field(ge=10, description="read timeout in seconds for HTTP request")
+ ] = 20
HTTP_REQUEST_NODE_MAX_BINARY_SIZE: PositiveInt = Field(
description="",
diff --git a/api/core/workflow/nodes/http_request/http_request_node.py b/api/core/workflow/nodes/http_request/http_request_node.py
index f6c8ea3c834..037a7a1848c 100644
--- a/api/core/workflow/nodes/http_request/http_request_node.py
+++ b/api/core/workflow/nodes/http_request/http_request_node.py
@@ -19,9 +19,9 @@ from core.workflow.nodes.http_request.http_executor import HttpExecutor, HttpExe
from models.workflow import WorkflowNodeExecutionStatus
HTTP_REQUEST_DEFAULT_TIMEOUT = HttpRequestNodeTimeout(
- connect=min(10, dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT),
- read=min(60, dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT),
- write=min(20, dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT),
+ connect=dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT,
+ read=dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT,
+ write=dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT,
)
@@ -96,12 +96,9 @@ class HttpRequestNode(BaseNode):
if timeout is None:
return HTTP_REQUEST_DEFAULT_TIMEOUT
- timeout.connect = min(timeout.connect or HTTP_REQUEST_DEFAULT_TIMEOUT.connect,
- dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT)
- timeout.read = min(timeout.read or HTTP_REQUEST_DEFAULT_TIMEOUT.read,
- dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT)
- timeout.write = min(timeout.write or HTTP_REQUEST_DEFAULT_TIMEOUT.write,
- dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT)
+ timeout.connect = timeout.connect or HTTP_REQUEST_DEFAULT_TIMEOUT.connect
+ timeout.read = timeout.read or HTTP_REQUEST_DEFAULT_TIMEOUT.read
+ timeout.write = timeout.write or HTTP_REQUEST_DEFAULT_TIMEOUT.write
return timeout
@classmethod
diff --git a/api/tests/unit_tests/configs/test_dify_config.py b/api/tests/unit_tests/configs/test_dify_config.py
index fb415483dd3..3f639ccacc4 100644
--- a/api/tests/unit_tests/configs/test_dify_config.py
+++ b/api/tests/unit_tests/configs/test_dify_config.py
@@ -19,6 +19,7 @@ def example_env_file(tmp_path, monkeypatch) -> str:
"""
CONSOLE_API_URL=https://example.com
CONSOLE_WEB_URL=https://example.com
+ HTTP_REQUEST_MAX_WRITE_TIMEOUT=30
"""
)
)
@@ -48,6 +49,12 @@ def test_dify_config(example_env_file):
assert config.API_COMPRESSION_ENABLED is False
assert config.SENTRY_TRACES_SAMPLE_RATE == 1.0
+ # annotated field with default value
+ assert config.HTTP_REQUEST_MAX_READ_TIMEOUT == 60
+
+ # annotated field with configured value
+ assert config.HTTP_REQUEST_MAX_WRITE_TIMEOUT == 30
+
# NOTE: If there is a `.env` file in your Workspace, this test might not succeed as expected.
# This is due to `pymilvus` loading all the variables from the `.env` file into `os.environ`.