-
Notifications
You must be signed in to change notification settings - Fork 967
Provide a way to complete a ClientRequestContext in Preprocessor
#6466
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?
Conversation
minwoox
left a comment
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.
Looks great. 👍
Left small suggestions. 😉
| if (!initializationTriggeredUpdater.compareAndSet(this, 0, 1)) { | ||
| return false; | ||
| } | ||
| acquireEventLoop(endpointGroup); |
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.
Probably, we don't need to call initializeResponseCancellationScheduler in acquireEventLoop?
| ctxExt.runContextCustomizer(); | ||
| } | ||
| try { | ||
| return execution.execute(ctx, req); |
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.
What do you think about moving the call to completeLogIfIncomplete from line 111 to here? It seems like it would prevent the case where an http response is returned in the pre decorator.
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.
Shouldn't we also change this line?
futureConverter, errorResponseFactory, req, false);
armeria/core/src/main/java/com/linecorp/armeria/internal/client/TailPreClient.java
Line 82 in 89e1a84
| futureConverter, errorResponseFactory, req, true); |
Additionally, this isn't related to this PR but shouldn't tryCompleteLog be true in these lines? cc @ikhoon
armeria/core/src/main/java/com/linecorp/armeria/client/retry/RetryingClient.java
Lines 325 to 328 in 51f0790
| (context, cause) -> HttpResponse.ofFailure(cause), ctxReq, false); | |
| } else { | |
| response = executeWithFallback(unwrap(), derivedCtx, | |
| (context, cause) -> HttpResponse.ofFailure(cause), ctxReq, false); |
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.
Shouldn't we also change this line? futureConverter, errorResponseFactory, req, false);
Understood that the intention is that completeLogIfIncomplete is already registered when preclients are invoked, and hence another callback doesn't need to be added
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6466 +/- ##
============================================
- Coverage 74.46% 74.16% -0.30%
- Complexity 22234 23023 +789
============================================
Files 1963 2061 +98
Lines 82437 86190 +3753
Branches 10764 11305 +541
============================================
+ Hits 61385 63926 +2541
- Misses 15918 16868 +950
- Partials 5134 5396 +262 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ikhoon
left a comment
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.
👍 👍
Motivation:
This issue was found while working on
GrpcServicesPreprocessorrefactoring.Currently, there is a bug where exceptions/response failures in
Preprocessordo not completectx.whenInitialized.e.g.
While normally this may not be an issue, gRPC relies on completion of this future to signal errors:
ref:
armeria/grpc/src/main/java/com/linecorp/armeria/internal/client/grpc/ArmeriaClientCall.java
Line 180 in 1a31f3e
I propose two modifications to resolve this issue:
PreClient#executecalling thread, it should complete the ctxctx.cancelis called (even beforectx.init) is called, it should complete the ctxModifications:
initializedflag to guard against concurrent initialization attemptsfinishInitializationis also modified to guard against concurrent callsinitAndFailmethod is introduced which acquires an event loop, initializes the cancellation scheduler, and completes the ctxctx.cancelwill triggerinitAndFailif the ctx is not initialized yetPreClient#executethrows an exception,initAndFailis calledClientUtil#initContextAnd*needs to be called. Hence, initialization is set only if an endpoint exists.responseCancellationScheduler.finishNowis called inDefaultClientRequestContext#failEarlyto recordcancellationCauseconsistently.XdsPreprocessorandRouterFilternow callsctx.cancelif a request is short-circuited beforectx.initis called.Result:
XdsPreprocessor-level are propagated to the user correctly when using gRPC.