-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duration of 0 in withMultipleHostAndPort
not rotating host.
#389
Comments
This is discussed in #319 which I added about a year ago. We never did anything else with it because we made sure our service code always uses a positive timeout and we also put a maximum number of failover attempts in #304. I think the correct answer is to change the code to require a positive timeout, because a zero timeout really isn't a timeout at all (again, see #319). But that's the way the code was when we started maintaining this project. Anyway, the constraint in the constructor of If someone wants to be cute and put a timeout of 1 nanosecond, it probably won't work but that's on them. Last, I think we can classify this as a bug and it can be changed in a patch or minor version, not requiring a major version bump. |
Thanks, I didn't realized there was a ticket already. My thought is that if zero duration is allowed, it would cycle through all the hosts without blacklisting.
The use case that I have is: use the local consul agent first and fallback to the cluster. If any issue occurred, it will proceed to the next available host. Seems like it can be simulated with some small positive timeout duration. |
It seems wrong to me to allow zero duration and never blacklist a target in a class named I can see why it's confusing though, since you need to read the documentation to know that Maybe your use case might be better served using a simpler Then, when constructing the For example, something like: // assume targets and timeoutMillis are already defined
var roundRobinStrategy = new RoundRobinConsulFailoverStrategy(targets, timeoutMillis);
var consul = Consul.builder()
.withPing(false)
.withFailoverInterceptorUsingStrategy(roundRobinStrategy)
.build() As a first guess, the implementation of Going further, we could add |
A round robin failover strategy make sense. I tried to do a simple implementation from your suggestion, but it need an extra state to know when to reset.
From this thread, the client should be thread safe: rickfast/consul-client#69 , so likely will need thread-local to store the current index. |
When
Duration.ofMillis(0)
is passed intowithMultipleHostAndPort
, only the first host is used. The expectation is that hosts will be rotated on subsequent uses but without blacklisting.The text was updated successfully, but these errors were encountered: