Need HTTP request retry to be configurable
See original GitHub issueDue 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:
- The
Mono
we return from the function given toHttpClient#mapConnect
. - The
Mono
returned from theConnectionProvider#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:
- Created a year ago
- Comments:9 (4 by maintainers)
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.
Let’s keep it for the moment if somebody wants to work on it …