fix: keep long-lived aiohttp ClientSession across async HTTP reports - #422
Merged
wu-sheng merged 2 commits intoSep 22, 2026
Merged
Conversation
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
approved these changes
Sep 22, 2026
wu-sheng
left a comment
Member
There was a problem hiding this comment.
LGTM. BTW, I fixed a found issue out of your codes.
Contributor
Author
|
Thanks for the review |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix aiohttp ClientSession closed after the first async HTTP report
When
SW_AGENT_ASYNCIO_ENHANCEMENT=trueandSW_AGENT_PROTOCOL=http(bothnon-default), the async HTTP reporter does:
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 /HttpProtocolAsyncso agentshutdown can release the session (the agent already calls
protocol.aclose()).