-
Notifications
You must be signed in to change notification settings - Fork 923
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
Set RequestContext.isTimedOut(true) on DNS, session, write timeout #5156
Conversation
ae89c0b
to
9396937
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5156 +/- ##
============================================
- Coverage 74.25% 73.92% -0.34%
- Complexity 19825 20023 +198
============================================
Files 1699 1722 +23
Lines 73046 73899 +853
Branches 9357 9406 +49
============================================
+ Hits 54239 54628 +389
- Misses 14371 14820 +449
- Partials 4436 4451 +15 ☔ View full report in Codecov by Sentry. |
core/src/main/java/com/linecorp/armeria/client/HttpClientDelegate.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/HttpChannelPool.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/SessionCreationTimeoutException.java
Outdated
Show resolved
Hide resolved
92426fb
to
d58b565
Compare
.build(); | ||
|
||
assertThat(reqCtx.isTimedOut()).isFalse(); | ||
assertThatThrownBy(() -> client.unwrap().execute(reqCtx, req).aggregate().join()) |
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.
assertThatThrownBy(() -> client.unwrap().execute(reqCtx, req).aggregate().join()) | |
assertThatThrownBy(() -> client.get("/").aggregate().join()) |
Hmm when I use WebClient.get("/")
directly, reqCtx.whenResponseCancelled().join()
not done infinitely 🤔
armeria/core/src/main/java/com/linecorp/armeria/client/ClientRequestContextBuilder.java
Line 144 in 863e27c
responseCancellationScheduler.init(eventLoop(), noopCancellationTask, 0, /* server */ false); |
I guess ClientRequestContextBuilder().build()
init cancellationScheduler
immediately, but WebClient didn't.
armeria/core/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.java
Lines 228 to 229 in 863e27c
this.responseCancellationScheduler = | |
new CancellationScheduler(TimeUnit.MILLISECONDS.toNanos(responseTimeoutMillis)); |
armeria/core/src/main/java/com/linecorp/armeria/internal/common/CancellationScheduler.java
Line 311 in 863e27c
addPendingTask(() -> finishNow0(cause)); |
On WebClient, it uses DefaultClientRequestContext
and it doesn't init()
the ClientRequestContext's cancellationScheduler immediately.
Just add task (e.g. ctx.cancel(cause)
) to pending task and execute it on init()
lazily later like below.
armeria/core/src/main/java/com/linecorp/armeria/internal/common/CancellationScheduler.java
Lines 129 to 132 in 863e27c
if (pendingTaskUpdater.compareAndSet(this, pendingTask, noopPendingTask)) { | |
if (pendingTask != null) { | |
pendingTask.run(); | |
} |
But to get reqCtx.whenCancelled()
completion, we need to init() cancellationScheduler.
So I used client.unwarp().execuite(reqCtx)
to use ClientRequestContext.builder().build() to init cancellationScheduler~!
I'm not sure it's correct, so feel free to share your opinion! I'll update PR 🙇
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.
I believe you can just use Clients.newContextCaptor()
if you would like to get ahold of the RequestContext
being used
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.
oh I tried to use Clients.newContextCaptor()
but cancellationScheduler
is still not init()
by this way so ClientRequestContext.isTimedOut()
return 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.
Looks good overall! Left some minor comments 🙇
core/src/main/java/com/linecorp/armeria/client/ClientRequestContext.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java
Outdated
Show resolved
Hide resolved
.build(); | ||
|
||
assertThat(reqCtx.isTimedOut()).isFalse(); | ||
assertThatThrownBy(() -> client.unwrap().execute(reqCtx, req).aggregate().join()) |
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.
I believe you can just use Clients.newContextCaptor()
if you would like to get ahold of the RequestContext
being used
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.
Took another look at this PR.
The way I see it there are two options (or actually three):
- Use
log.responseCause
to determine whether a request/response has timed out (or actuallylog().getIfAvailable(RequestLogProperty.RESPONSE_CAUSE).responseCause();
) - Modify
responseCancellationScheduler
so that either
1.init
is called at an earlier timing. Ideally, this would involve scheduling timeouts for each step (dns, connect, write, etc..) usingctx.cancellationScheduler
.
2. modify the behavior so thatcancel()
also executes pending tasks.
I think 1 or 2-2 is probably a realistic direction for this PR. Let me discuss with the other tomorrow morning 🙇
If there's some discussion progress about direction, feel free to share to me~! 🙇 |
aha~ I checked #5212. thanks for sharing! |
core/src/main/java/com/linecorp/armeria/client/ClientRequestContext.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/SessionCreationTimeoutException.java
Outdated
Show resolved
Hide resolved
oh~ I'll update this PR on this weekend. thanks! :) |
084bf58
to
a8aa4a6
Compare
a8aa4a6
to
6c76245
Compare
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.
Changes look good to me 👍 👍 👍
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.
Just one nit. Thank! 😄
core/src/main/java/com/linecorp/armeria/client/SessionProtocolNegotiationException.java
Outdated
Show resolved
Hide resolved
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.
Thanks, @injae-kim! 🙇♂️🙇♂️
Related issue #4935
Motivation:
DnsTimeoutException
should also settrue
toctx.isTimedOut()
. #4935, we found thatRequestContext.isTimedout
is not set true on DNS, session creation, write timeout so we need to fix itModifications:
RequestContext.isTimedOut(true)
on DNS, session, write timeout byctx.cancel(TimeoutException.class)
Result:
RequestContext.isTimedout
is set true well on DNS, session, write timeout tooDnsTimeoutException
should also settrue
toctx.isTimedOut()
. #4935