mirror of
https://github.com/langgenius/dify.git
synced 2026-08-01 09:50:50 +08:00
fix(auth): add bounded timeout to WaterCrawl credential validation (#39824)
This commit is contained in:
parent
97e9d8be5a
commit
4557f127ff
@ -6,6 +6,10 @@ import httpx
|
||||
|
||||
from services.auth.api_key_auth_base import ApiKeyAuthBase, AuthCredentials
|
||||
|
||||
# Explicit bounded timeout for credential-validation requests so a slow or
|
||||
# hanging WaterCrawl endpoint cannot block the worker indefinitely.
|
||||
_CREDENTIAL_TIMEOUT = httpx.Timeout(10.0)
|
||||
|
||||
|
||||
class WatercrawlAuth(ApiKeyAuthBase):
|
||||
def __init__(self, credentials: AuthCredentials):
|
||||
@ -33,7 +37,7 @@ class WatercrawlAuth(ApiKeyAuthBase):
|
||||
return {"Content-Type": "application/json", "X-API-KEY": self.api_key}
|
||||
|
||||
def _get_request(self, url, headers):
|
||||
return httpx.get(url, headers=headers)
|
||||
return httpx.get(url, headers=headers, timeout=_CREDENTIAL_TIMEOUT)
|
||||
|
||||
def _handle_error(self, response):
|
||||
if response.status_code in {402, 409, 500}:
|
||||
|
||||
@ -77,6 +77,7 @@ class TestWatercrawlAuth:
|
||||
mock_get.assert_called_once_with(
|
||||
"https://app.watercrawl.dev/api/v1/core/crawl-requests/",
|
||||
headers={"Content-Type": "application/json", "X-API-KEY": "test_api_key_123"},
|
||||
timeout=httpx.Timeout(10.0),
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user