question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need HTTP request retry to be configurable

See original GitHub issue

Due to our infrastructure, we need to retry requests, primarily connection establishment related like connection failed/timed out, SSL handshake timeout, etc… To date, we have tried doing this by adding retry to the following:

  1. The Mono we return from the function given to HttpClient#mapConnect.
  2. The Mono returned from the ConnectionProvider#acquire (via wrapping)

The first option is more promising (thanks @violetagg !), but it still comes with some negatives. We’re thinking the second will not work for all the cases we want to retry.

At this time, we’re thinking the best approach is to make the retry more configurable. Something like Apache HTTP client retry interface, but not quite that opened ended. I totally get that this is not a slam-dunk on whether or not this should be added given reactor-core’s built-in retry concept, but the biggest issue we have using the mapConnect approach above is making sure we don’t retry if any application data has been sent across the wire (e.g. request line, headers). The only thing we currently have to solve that problem is to register a ConnectionObserver, but this seems a little too coupled with reactor-http implementation.

This was discussed in gitter here.

The bulk of the retry code I refer to for mapConnect is:

final AtomicBoolean headersSent = new AtomicBoolean(false);

final Retry retryPolicy = Retry.from(companion -> companion.map(sig -> {
    if (!headersSent.get() && sig.totalRetries() < config.getMaxRequestRetry()) {
        return sig.totalRetries();
    }
    throw Exceptions.propagate(sig.failure());
}));

return httpClient
    .observe((connection, newState) -> {
        if (newState == ConnectionObserver.State.CONNECTED) {
            headersSent.set(true);
        }
    }).mapConnect(conn -> {
        return conn.retryWhen(retryPolicy);
    });

Motivation

We have many cases where infrastructure problems can be ‘worked around’ by doing an immediate request retry. These exceptional cases are broader than what reactor-http currently retries.

Desired solution

Ability to customize retry behavior to suit our infrastructure. Basically, to mimic what we were doing with Apache HTTP client:)

Considered alternatives

Detailed above.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
crankydillocommented, Aug 23, 2022

Totally makes sense. Not sure why I didn’t do that to start with. I will try to get this done within the next week or so.

0reactions
violetaggcommented, Oct 3, 2022

I’m not sure when I’ll be able to get back to this. At this time, my team is not asking for it in the near-term. I’m fine closing this if you don’t feel it’s a feature you need or want to track.

Let’s keep it for the moment if somebody wants to work on it …

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Retries to HTTP requests - DEV Community ‍ ‍
First, declare an array of status codes we want to check for. You could also add this as part of the configuration, especially...
Read more >
Best Practices for Retry - Denali Balser
A retry of a request should only be considered when there is a chance of success- for example, in response to error codes...
Read more >
Retry HTTP Request with Backoff Strategy - Akinjide Bankole
Retrying HTTP Request makes our application more stable and a reliable strategy is using combination of a timeout and some retry condition ...
Read more >
Implement HTTP call retries with exponential backoff with Polly
You typically also need to reference the extension package Microsoft.Extensions.Http.Polly . Configure a client with Polly's Retry policy, ...
Read more >
Configuring Retry parameters for HTTP HTTP(s) Transport
Users can configure the parameters for retry of the request messages, in case, the request message is not delivered due to timeout or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found