Skip to content

[server] Add retriable authentication exception. #845

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

loserwang1024
Copy link
Collaborator

Purpose

Linked issue: close #844

Brief change log

Tests

com.alibaba.fluss.rpc.netty.authenticate.AuthenticationTest#testRetirableAuthenticateException

API and Format

Documentation

@loserwang1024 loserwang1024 requested review from wuchong and luoyuxia May 9, 2025 07:56
@@ -319,7 +319,7 @@ private void handleAuthenticateRequest(
if (!authenticator.isCompleted()) {
byte[] token = authenticateRequest.getToken();
byte[] challenge = authenticator.evaluateResponse(token);
if (!authenticator.isCompleted() && challenge != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the removal of !authenticator.isCompleted() necessary? I though the authenticator.evaluateResponse may change status of authenticator into complete and don't need to send challenge.

}

private void handleAuthenticateResponse(ApiMessage response, Throwable cause) {
if (cause != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we still authenticate in the ServerConnection instead of a separate channel handler? It increases the complexity that the authenticator and switchState out of the lock and may cause problems.

I though we only need to re-auth here when the cause is retrable auth exception. In the future, we should also add re-auth logic here for expired authentications. We can also maintain backoff in ServerConnection as it is per-connection.

new AuthenticateRequest()
.setToken(token)
.setProtocol(authenticator.protocol());
pendingRequest = request;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to remember the auth request? Can we just re-send the auth request from byte[0]? We should try to avoid maintaining states.

private void handleAuthenticateResponse(ApiMessage response, Throwable cause) {
if (cause != null) {
if (cause instanceof RetriableAuthenticationException
&& retryAuthNum < MAX_RETRY_AUTH_NUM) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to set max retry num and allow the request timeout by netty client. Sender also doesn't have max retry on RetriableException.

} else {
callback.onAuthenticateFailure(
new IllegalStateException(
new IllegalStateException(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why nested IllegalStateException?

private static final Logger LOG = LoggerFactory.getLogger(NettyAuthenticationHandler.class);
private static final Random RANDOM = new Random();
private static final long BASE_BACKOFF_MS = 500L;
private static final long MAX_BACKOFF_MS = 60000L;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BASE_BACKOFF_MS -> 100L (better initial latency) and MAX_BACKOFF_MS -> 5s (not idle too long)

Comment on lines +140 to +146
private long calculateBackOff() {
// Exponential backoff with jitter
long backOff = BASE_BACKOFF_MS * (1L << retryAuthNum);
backOff = Math.min(backOff, MAX_BACKOFF_MS); // Ensure it does not exceed maxBackOffMs
long jitter = (long) (backOff * JITTER_FACTOR * RANDOM.nextDouble());
return backOff + jitter;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce Kafka ExponentialBackoff and ExponentialBackoffTest for the verified backoff util. The jitter should consider -20% ~ + 20%.

@scriptforfivem
Copy link

Impressive project structure! The architecture really demonstrates solid design principles.

@fivemhostingserver
Copy link

The performance optimizations here are quite clever. Nice engineering work!

@fivemeyestore
Copy link

This is a well-structured codebase. I appreciate the clean separation of concerns.

@fivemserverhostings
Copy link

The performance optimizations here are quite clever. Nice engineering work!

@eyesgodcode
Copy link

This is a well-structured codebase. I appreciate the clean separation of concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add retriable authentication exception
7 participants