Git Product home page Git Product logo

Comments (3)

mna avatar mna commented on May 27, 2024

Hello Adam,

The timeout applies to the request as a whole, including retries, since it is set on the HTTP client. I agree that it would be nice to have a per-attempt timeout too, though I'm not sure it could be easily added. You could try setting the http.Transport's ResponseHeaderTimeout, if your slow requests hang on sending the headers, that should work and would be retried with a RetryTemporaryErr.

Hope this helps,
Martin

from rehttp.

abemedia avatar abemedia commented on May 27, 2024

I actually had a look through the code and realised it wouldn't be that simple not long after submitting the issue.
How about adding a second context which gets reset at the beginning of each roundtrip? Or possibly a method that resets the main context (for use-cases where solely having a timeout per request is desirable).

from rehttp.

mna avatar mna commented on May 27, 2024

How would that context actually cancel the in-flight roundtrip when the deadline hits? The Request.Cancel channel belongs to the caller, it can't be used for that (it means "cancel the whole request", so it has to cancel any retries).

It was pretty much by design that whole request timeouts apply as a whole (and not per-attempt), as that gives a bounded time limit to the request regardless of potential retries. As I said, it sure would be nice to have both options, but I don't see how it could be done at the Transport level (there are not that many hooks available). If you want to retry in case of a timeout, I think a custom http.Client (more like a Doer interface wrapper, what I mentioned in the blog post here: https://0value.com/Let-the-Doer-Do-it) would make more sense: wrap the http.Client, and retry if the error is a timeout.

That being said, I'm open to add a per-attempt timeout feature in rehttp if it fits cleanly in the API. Maybe it can be done at the net.Conn level (which is passed by the Dialer to the Transport). If so it would work as-is as far as rehttp is concerned, probably worth trying out.

from rehttp.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.