Skip to content

fix(feishu): finalize remote document downloads inside httpx.AsyncClient context#18502

Closed
beibi9966 wants to merge 1 commit into
NousResearch:mainfrom
beibi9966:fix/feishu-httpx-remote-download-lifecycle
Closed

fix(feishu): finalize remote document downloads inside httpx.AsyncClient context#18502
beibi9966 wants to merge 1 commit into
NousResearch:mainfrom
beibi9966:fix/feishu-httpx-remote-download-lifecycle

Conversation

@beibi9966

Copy link
Copy Markdown
Contributor

Summary

Feishu outbound document fetch (_download_remote_document) previously read response.headers / response.content after exiting async with httpx.AsyncClient(...). That can leave pooled HTTP connections in an awkward shutdown window and adds avoidable pressure on process file descriptors in long-running gateways (see #18451).

This change snapshots Content-Type and the response body while the client context is still active, then passes bytes into cache_document_from_bytes.

Test plan

  • pytest tests/gateway/test_feishu.py::TestAdapterBehavior::test_download_remote_document_reads_response_before_httpx_client_closes -q

Related

…context

Ensure response bytes and Content-Type are captured before AsyncClient teardown
to avoid lingering TCP halves under gateway-wide connection pressure (NousResearch#18451).

Adds a regression test that orders content reads before client exit.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/feishu Feishu / Lark adapter labels May 1, 2026
teknium1 pushed a commit that referenced this pull request May 2, 2026
…ent context (#18502)

Snapshot Content-Type and body while the client context is still
active so pooled connections fully release on exit. Previously the
read happened after `async with httpx.AsyncClient(...)` returned —
which works today only because httpx eagerly buffers non-streaming
responses; a future refactor to `.stream()` would silently read-
after-close.

Part of the #18451 connection-hygiene audit. Salvage of #18502.
teknium1 added a commit that referenced this pull request May 2, 2026
@teknium1

teknium1 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Merged via #18766 — your Feishu hygiene fix landed on current main with authorship preserved (rebase-merge). Widened the scope beyond your PR after auditing every persistent httpx/aiohttp client in the gateway tree: also closed a WhatsApp aiohttp leak (bare await self._http_session.post() that held responses in CLOSE_WAIT until GC) and tightened httpx.AsyncClient(limits=...) across all six persistent-client platforms (QQ Bot, WeCom, DingTalk, Signal, BlueBubbles, WeCom-callback) so idle keepalive sockets drain in 2s instead of httpx's default 5s — reduces aggregate fd pressure behind proxies like Cloudflare Warp.

Thanks for the initial catch — it triggered the broader audit.

#18766

@teknium1 teknium1 closed this May 2, 2026
nickdlkk pushed a commit to nickdlkk/hermes-agent that referenced this pull request May 11, 2026
…ent context (NousResearch#18502)

Snapshot Content-Type and body while the client context is still
active so pooled connections fully release on exit. Previously the
read happened after `async with httpx.AsyncClient(...)` returned —
which works today only because httpx eagerly buffers non-streaming
responses; a future refactor to `.stream()` would silently read-
after-close.

Part of the NousResearch#18451 connection-hygiene audit. Salvage of NousResearch#18502.
nickdlkk pushed a commit to nickdlkk/hermes-agent that referenced this pull request May 11, 2026
jsboige pushed a commit to jsboige/hermes-agent that referenced this pull request May 14, 2026
…ent context (NousResearch#18502)

Snapshot Content-Type and body while the client context is still
active so pooled connections fully release on exit. Previously the
read happened after `async with httpx.AsyncClient(...)` returned —
which works today only because httpx eagerly buffers non-streaming
responses; a future refactor to `.stream()` would silently read-
after-close.

Part of the NousResearch#18451 connection-hygiene audit. Salvage of NousResearch#18502.
jsboige pushed a commit to jsboige/hermes-agent that referenced this pull request May 14, 2026
dannyJ848 pushed a commit to dannyJ848/hermes-agent that referenced this pull request May 17, 2026
…ent context (NousResearch#18502)

Snapshot Content-Type and body while the client context is still
active so pooled connections fully release on exit. Previously the
read happened after `async with httpx.AsyncClient(...)` returned —
which works today only because httpx eagerly buffers non-streaming
responses; a future refactor to `.stream()` would silently read-
after-close.

Part of the NousResearch#18451 connection-hygiene audit. Salvage of NousResearch#18502.
dannyJ848 pushed a commit to dannyJ848/hermes-agent that referenced this pull request May 17, 2026
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…ent context (NousResearch#18502)

Snapshot Content-Type and body while the client context is still
active so pooled connections fully release on exit. Previously the
read happened after `async with httpx.AsyncClient(...)` returned —
which works today only because httpx eagerly buffers non-streaming
responses; a future refactor to `.stream()` would silently read-
after-close.

Part of the NousResearch#18451 connection-hygiene audit. Salvage of NousResearch#18502.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…ent context (NousResearch#18502)

Snapshot Content-Type and body while the client context is still
active so pooled connections fully release on exit. Previously the
read happened after `async with httpx.AsyncClient(...)` returned —
which works today only because httpx eagerly buffers non-streaming
responses; a future refactor to `.stream()` would silently read-
after-close.

Part of the NousResearch#18451 connection-hygiene audit. Salvage of NousResearch#18502.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
Seven74AI pushed a commit to Seven74AI/hermes-agent that referenced this pull request Jun 13, 2026
…ent context (NousResearch#18502)

Snapshot Content-Type and body while the client context is still
active so pooled connections fully release on exit. Previously the
read happened after `async with httpx.AsyncClient(...)` returned —
which works today only because httpx eagerly buffers non-streaming
responses; a future refactor to `.stream()` would silently read-
after-close.

Part of the NousResearch#18451 connection-hygiene audit. Salvage of NousResearch#18502.
Seven74AI pushed a commit to Seven74AI/hermes-agent that referenced this pull request Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/feishu Feishu / Lark adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants