Skip to content

fix: keep long-lived aiohttp ClientSession across async HTTP reports - #422

Merged
wu-sheng merged 2 commits into
apache:masterfrom
songzhendong:fix/http-reporter-session-silent-drop
Sep 22, 2026
Merged

wu-sheng merged 2 commits into
apache:masterfrom
songzhendong:fix/http-reporter-session-silent-drop

Conversation

@songzhendong

@songzhendong songzhendong commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Fix aiohttp ClientSession closed after the first async HTTP report

  • Add a unit test to verify that the fix works.
  • Explain briefly why the bug exists and how to fix it.

When SW_AGENT_ASYNCIO_ENHANCEMENT=true and SW_AGENT_PROTOCOL=http (both
non-default), the async HTTP reporter does:

async with self.client as client:
    await client.post(...)

ClientSession.__aexit__ closes the long-lived session after the first request.
Later heartbeats / segment / log reports fail for the rest of the process
lifetime (telemetry permanently dropped until restart). Application traffic is
unaffected.

Introduced in #316.

Fix: use async with self.client.post(...) so only the response is closed,
and add aclose() on the async HTTP clients / HttpProtocolAsync so agent
shutdown can release the session (the agent already calls protocol.aclose()).

Replace async-with on the shared ClientSession (closes it after the first
request) with async-with on the response. Add aclose() for session cleanup.
@wu-sheng wu-sheng added the enhancement New feature or request label Sep 22, 2026
@wu-sheng wu-sheng added this to the 1.4.0 milestone Sep 22, 2026

@wu-sheng wu-sheng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. BTW, I fixed a found issue out of your codes.

@songzhendong

Copy link
Copy Markdown
Contributor Author

Thanks for the review

@wu-sheng
wu-sheng merged commit 5666826 into apache:master Sep 22, 2026
172 of 175 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants