Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Redirect handling does not close old Response, leading to resources not being closed #299

Closed
@markretallack

Description

@markretallack

Environment

  • Python Version: 3.11.5
  • kiota-http version: 1.3.0
  • OS: Linux (openSuse)

Stack trace (if available)

Describe the bug
The RedirectHandler class in the Microsoft Kiota HTTP Python library is currently experiencing an issue where the original response, containing the new URL, is not closed before performing a redirect. This behaviour results in httpcore async layer running out of streams, reaching a limit of 100 streams.

To Reproduce

  1. Execute a request using the RedirectHandler in a scenario that triggers a redirect. I used the ms graph sdk with a drive item content.get () call to download multiple files (over 100).
  2. Observe the httpcore async behaviour after a redirect, after 100, the call to content.get() blocks (if using ms graph sdk).

Expected behavior
I think the original response should be closed properly before the redirect is performed to prevent httpcore async from running out of streams.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
To "fix" the issue, I have used the following code, not sure if this is the correct solution.

            if redirect_location and current_options.should_redirect:
                max_redirect -= 1
                if not self.increment(response, max_redirect, history[:]):
                    break
                _redirect_span.set_attribute(REDIRECT_COUNT_KEY, len(history))
                new_request = self._build_redirect_request(request, response)
                request = new_request
                # make sure the response is closed
                await response.aclose()
                continue

            response.history = history
            break

Metadata

Metadata

Assignees

Labels

WIPbugSomething isn't working

Type

No type

Projects

Status

Done ✔️

Relationships

None yet

Development

No branches or pull requests

Issue actions