Skip to content

fix: close streaming responses before retrying#565

Merged
baywet merged 2 commits into
microsoft:mainfrom
Kashyap456:fix/retry-handler-close-responses
Jun 7, 2026
Merged

fix: close streaming responses before retrying#565
baywet merged 2 commits into
microsoft:mainfrom
Kashyap456:fix/retry-handler-close-responses

Conversation

@Kashyap456
Copy link
Copy Markdown
Contributor

@Kashyap456 Kashyap456 commented Jun 5, 2026

Overview

This PR closes a response in RetryHandler's retry loop before response gets reassigned by the retry loop. This allows the connection that produced the response to get released back to its connection pool to serve another request.

Related Issue

Fixes #564

Testing Instructions

Added test_retried_responses_are_closed to packages/http/httpx/tests/middleware_tests/test_retry_handler.py to verify retried responses are closed (so their connections are released back to the pool). It drives the real RetryHandler with a MockTransport returning 429, 429, 200, and asserts the two retried responses report is_closed while the returned 200 stays open. Runs in the existing suite via pytest.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 5, 2026

@Kashyap456 Kashyap456 marked this pull request as ready for review June 5, 2026 19:53
@Kashyap456 Kashyap456 requested a review from a team as a code owner June 5, 2026 19:53
Copy link
Copy Markdown
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Please make sure you sign the CLA (see the bot message)

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Jun 5, 2026
@baywet baywet enabled auto-merge June 5, 2026 20:23
@Kashyap456
Copy link
Copy Markdown
Contributor Author

sorry for the delay here, just making sure I have the right approvals to sign the CLA on behalf of my company, because I made this change as part of work

@baywet
Copy link
Copy Markdown
Member

baywet commented Jun 6, 2026

No worries, we're working on a deployment pipeline migration anyway.

@Kashyap456
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@baywet baywet merged commit d5ac3ee into microsoft:main Jun 7, 2026
53 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Jun 7, 2026
@Kashyap456
Copy link
Copy Markdown
Contributor Author

I was advised by my employer to sign on my own behalf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

[Bug] Retry handling does not close retried responses, which leaks httpx connections

2 participants