mirror of
https://github.com/langgenius/dify.git
synced 2026-06-23 12:31:13 +08:00
fix: add bounded timeout to Firecrawl credential validation (#37638)
This commit is contained in:
parent
16fd55ab58
commit
89d4fe91bc
@ -5,6 +5,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 Firecrawl endpoint cannot block the worker indefinitely.
|
||||
_CREDENTIAL_TIMEOUT = httpx.Timeout(10.0)
|
||||
|
||||
|
||||
class FirecrawlAuth(ApiKeyAuthBase):
|
||||
def __init__(self, credentials: AuthCredentials):
|
||||
@ -42,7 +46,7 @@ class FirecrawlAuth(ApiKeyAuthBase):
|
||||
return f"{self.base_url.rstrip('/')}/{path.lstrip('/')}"
|
||||
|
||||
def _post_request(self, url, data, headers):
|
||||
return httpx.post(url, headers=headers, json=data)
|
||||
return httpx.post(url, headers=headers, json=data, timeout=_CREDENTIAL_TIMEOUT)
|
||||
|
||||
def _handle_error(self, response):
|
||||
try:
|
||||
|
||||
@ -86,6 +86,7 @@ class TestFirecrawlAuth:
|
||||
"https://api.firecrawl.dev/v1/crawl",
|
||||
headers={"Content-Type": "application/json", "Authorization": "Bearer test_api_key_123"},
|
||||
json=expected_data,
|
||||
timeout=httpx.Timeout(10.0),
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user