[bug] Firecrawl web_search/web_fetch leak an unclosed httpx.AsyncClient pool per tool call
Before you start
- I searched existing issues and this is not a duplicate.
- I can reproduce this on the latest
main.
Problem summary
Every web_search / web_fetch call through the Firecrawl community tools constructs a fresh AsyncFirecrawlApp and abandons it without closing. Since the migration to the async client (#5786), that app eagerly owns an httpx.AsyncClient-backed connection pool which is never closed by anyone — one unclosed pool per tool call on a long-running gateway.
Affected area(s)
Backend — backend/packages/harness/deerflow/community/firecrawl/tools.py
Root cause
_get_firecrawl_client() builds AsyncFirecrawlApp(...) per call (unchanged from the sync era). But unlike the sync v2 HttpClient (a stateless config holder that issues requests per call and holds no session), the async path in firecrawl-py 4.23.0 is stateful:
AsyncFirecrawl.__init__→AsyncFirecrawlClient.__init__→AsyncHttpClient.__init__→self._client = httpx.AsyncClient(...)(eagerly created);AsyncHttpClient.close()exists but the wrapper classes expose no teardown of their own (noclose/aclose/async withonAsyncFirecrawlorAsyncFirecrawlClient).
So the tool's await client.search(...) uses one request out of a freshly built pool and then drops the whole object; nothing ever calls the pool's close().
Evidence
Static: the tools never touch any close path, and the SDK exposes none they could call. Runtime probe on current main (firecrawl-py 4.23.0):
import firecrawl
app = firecrawl.AsyncFirecrawlApp(api_key="k")
v2 = app._v2_client
print(type(v2.async_http_client._client).__name__, v2.async_http_client._client.is_closed)
# AsyncClient False <- constructed open, and there is no public way to close it
print(hasattr(app, "close"), hasattr(v2, "close"))
# False FalseImpact
- One
httpx.AsyncClient(plus its pooled sockets and any keep-alive state) perweb_search/web_fetchcall, retained until GC gets to it; async pools are not reliably finalized without the owning loop closing them. - Also loses connection reuse: every call pays a fresh TLS handshake instead of pooling across calls.
The sibling providers follow two clean in-repo patterns: scoped async with httpx.AsyncClient(...) (jina_ai, infoquest, crawl4ai, ...) or create-then-finally: await client.close() (tavily, #5784). Firecrawl is the only community tool holding an SDK client that is neither scoped nor closed.
Expected behavior
The per-call client's async pool is closed when the tool call ends, on both success and error paths.
Suggested implementation direction
- Close the pool in a
finallyon both tools, reaching the only available handle (client._v2_client.async_http_client.close()) through a small best-effort helper — the declared rangefirecrawl-py>=1.15.0includes versions without_v2_client, and afinallyteardown must never mask the tool's own result. - Tests: per-call close is awaited (search + fetch); the helper closes a real SDK pool (
is_closedflips toTrue); a client without_v2_clientdegrades to a no-op.
I have a fix ready and will link the PR here.
Source: bytedance/deer-flow