-
Notifications
You must be signed in to change notification settings - Fork 973
Add retry limiter support #6318
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
e2eaf8f
1ad33f4
d224ed2
0255f18
805b228
90ceda0
8ca3ae5
e1614d0
ea663f5
1fe7617
f49c3bd
a8095c8
ed307b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| import com.linecorp.armeria.client.ClientRequestContext; | ||
| import com.linecorp.armeria.common.HttpHeaders; | ||
| import com.linecorp.armeria.common.logging.RequestLog; | ||
| import com.linecorp.armeria.common.logging.RequestLogProperty; | ||
| import com.linecorp.armeria.internal.common.InternalGrpcWebTrailers; | ||
|
|
||
| /** | ||
|
|
@@ -178,10 +179,11 @@ public boolean shouldRetry(ClientRequestContext ctx, int numAttemptsSoFar) { | |
| */ | ||
| @Override | ||
| public void onCompletedAttempt(ClientRequestContext ctx, RequestLog requestLog, int numAttemptsSoFar) { | ||
| // Exception flow, no response available, do nothing. | ||
| if (requestLog.responseCause() != null) { | ||
| // Check if response headers and trailers are available if not we don't have a valid response | ||
| if (!requestLog.isAvailable(RequestLogProperty.RESPONSE_HEADERS, RequestLogProperty.RESPONSE_TRAILERS)) { | ||
| return; | ||
| } | ||
|
|
||
| // Extract the headers to be able to evaluate the gRPC status | ||
| // Check HTTP trailers first, because most gRPC responses have non-empty payload + trailers. | ||
| HttpHeaders maybeGrpcTrailers = requestLog.responseTrailers(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the request log does not have trailers, we will throw an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed 👍 |
||
|
|
@@ -203,9 +205,9 @@ public void onCompletedAttempt(ClientRequestContext ctx, RequestLog requestLog, | |
| final String status = maybeGrpcTrailers.get("grpc-status"); | ||
| final boolean decrement = retryableStatuses.contains(status); | ||
|
|
||
| while (true) { | ||
| boolean updated; | ||
| do { | ||
| final int currentCount = tokenCount.get(); | ||
| final boolean updated; | ||
| if (decrement) { | ||
| if (currentCount == 0) { | ||
| break; | ||
|
|
@@ -219,10 +221,7 @@ public void onCompletedAttempt(ClientRequestContext ctx, RequestLog requestLog, | |
| final int incremented = currentCount + tokenRatio; | ||
| updated = tokenCount.compareAndSet(currentCount, Math.min(incremented, maxTokens)); | ||
| } | ||
| if (updated) { | ||
| break; | ||
| } | ||
| } | ||
| } while (!updated); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do this but then you also have to cover the exceptional case with
handleExceptionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test case for this would be great