You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RedirectHandler leaves streaming responses open on redirect errors, exhausting the connection pool #900
Current main: 37b270459f391768df698142c741945365cd3191
Local microsoft-kiota-http and microsoft-kiota-abstractions 1.18.0 sources
Bug
RedirectHandler.send() leaves the last streaming response open when it raises RedirectError after exhausting the redirect limit. The same happens if _build_redirect_request() raises, for example because the redirect changes schemes and allow_redirect_on_scheme_change is false, the location has an invalid port, or a custom sensitive-header callback raises.
The successful redirect path calls await response.aclose() only after constructing the next request. The error paths exit before reaching that cleanup, and the caller never receives the response to close it.
Reproduction
With a localhost HTTP/1.1 endpoint returning a 302 and a nonempty body, a real httpx.AsyncHTTPTransport limited to one connection, and RedirectHandlerOption(max_redirect=0):
Send a request through RedirectHandler to the redirect endpoint.
Catch the expected RedirectError.
Send an ordinary request through the same handler/transport to a 200 endpoint.
On current main the second request raises httpx.PoolTimeout. Closing the discarded response before propagating the first error makes that second request return 200. This uses a local server, not Microsoft Graph or a live tenant.
A small in-memory check also shows the missing cleanup:
Close responses that are being discarded on redirect-limit or request-construction errors, while keeping returned responses open for the caller. In particular, successful final responses, disabled redirects, and an increment() override that stops redirect handling must retain their current ownership behavior.
A local candidate has nine regression/control cases: six fail on main, all nine pass with the candidate. The native HTTPX package suite passes before (227 tests) and after (236 tests). These are Linux/Python 3.10 results, not full-monorepo or hosted-CI validation.
This is separate from #565, which closes responses discarded by RetryHandler, and #735, which ends redirect tracing spans.
Would you welcome a focused PR for this cleanup?
AI assistance was used for diagnosis, patch preparation and test execution.
Activity