Skip to content

Commit

Permalink
Add handling for "etcdserver: revision of auth store is old" error ex…
Browse files Browse the repository at this point in the history
…perienced by customers when Role changes are made to the ETCD Cluster.

We are seeing a use case when ETCD Role grants are updated we are getting an error "etcdserver: revision of auth store is old" on all JETCD clients right after the grant is applied. The only fix now is for the client to restart and reconnect.

ETCD Cluster config:

ETCD_AUTH_TOKEN: jwt,pub-key=/auth-token/authToken.pub,priv-key=/auth-token/authToken.key,sign-method=RS256,ttl=8h

Signed-off-by: darvay <darvay@apple.com>
  • Loading branch information
darvay committed Nov 7, 2022
1 parent cadde88 commit d76e26d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ public <S, T> CompletableFuture<T> execute(
if (Errors.isInvalidTokenError(error)) {
authCredential().refresh();
}
if (Errors.isAuthStoreExpired(error)) {
authCredential().refresh();
}
if (!execution.retryOn(error)) {
// permanent failure
wrappedFuture.completeExceptionally(error);
Expand Down
4 changes: 4 additions & 0 deletions jetcd-core/src/main/java/io/etcd/jetcd/impl/Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.RetryPolicy;

import static io.etcd.jetcd.support.Errors.isAuthStoreExpired;
import static io.etcd.jetcd.support.Errors.isInvalidTokenError;

abstract class Impl {
Expand Down Expand Up @@ -113,6 +114,9 @@ protected <S, T> CompletableFuture<T> execute(
if (isInvalidTokenError(status)) {
connectionManager.authCredential().refresh();
}
if (isAuthStoreExpired(status)) {
connectionManager.authCredential().refresh();
}
return doRetry.test(status);
})
.onRetriesExceeded(e -> logger.warn("maximum number of auto retries reached"))
Expand Down
11 changes: 11 additions & 0 deletions jetcd-core/src/main/java/io/etcd/jetcd/support/Errors.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public final class Errors {
public static final String NO_LEADER_ERROR_MESSAGE = "etcdserver: no leader";
public static final String INVALID_AUTH_TOKEN_ERROR_MESSAGE = "etcdserver: invalid auth token";
public static final String ERROR_AUTH_STORE_OLD = "etcdserver: revision of auth store is old";

private Errors() {
}
Expand All @@ -39,6 +40,16 @@ public static boolean isInvalidTokenError(Status status) {
&& INVALID_AUTH_TOKEN_ERROR_MESSAGE.equals(status.getDescription());
}

public static boolean isAuthStoreExpired(Throwable e) {
Status status = Status.fromThrowable(e);
return isAuthStoreExpired(status);
}

public static boolean isAuthStoreExpired(Status status) {
return (status.getCode() == Status.Code.UNAUTHENTICATED || status.getCode() == Status.Code.INVALID_ARGUMENT)
&& ERROR_AUTH_STORE_OLD.equals(status.getDescription());
}

public static boolean isHaltError(final Status status) {
return status.getCode() != Status.Code.UNAVAILABLE && status.getCode() != Status.Code.INTERNAL;
}
Expand Down

0 comments on commit d76e26d

Please sign in to comment.