Skip to content

Retries on response.read and response.aread can't be handled inside RetryTransport #29

@vgavro

Description

@vgavro

Currently i got ReadTimeout and RemoteProtocolError("peer closed connection without sending complete message body ...") on httpx.Client.get, which is not handled on Transport level because errors raised during reading response, not returning response from Transport (which is expected by httpx API).
Transport is only returning response on receiving headers, but body fetching on Response.read/Response.aread is happening inside client logic.

Obviously, this should be mentioned in README, getting ReadTimeout on Client(transport=RetryTransport()).get() without any retries in logs looks like a bug (while it's expected behaviour).

How this could be solved:

  1. class httpx.RetryClient(httpx.Client) and wrap stream/get/... there, or maybe RetryClient(original_client)
    We should use response.extensions["retries"] to pass retry object with left attempts.

  2. resp = retry_response_read(client, "GET", url, **kwargs) (same as above, more explicit)

  3. Maybe create wrapper and apply it on transport level like: response.stream = RetryStreamWrapper(response.stream, self.retry)
    Huge downsides i'm seeing here - we need to re-initiate request to get new response(?), which can be totally unexpected for cases like: resp = client.get(url); print(resp.headers()); resp.read()
    here either we update resp object, either return body of new (other) response - both approaches are bad if we need to send new request, of course.

  4. other ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions