fix(auth): add bounded timeout to WaterCrawl credential validation (#39824)

This commit is contained in:
Chester 2026-07-31 21:52:02 +08:00 committed by GitHub
parent 97e9d8be5a
commit 4557f127ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -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}:

View File

@ -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(