Set RequestContext.isTimedOut(true) on DNS, session, write timeout#5156
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. |
92426fb to
d58b565
Compare
| .build(); | ||
|
|
||
| assertThat(reqCtx.isTimedOut()).isFalse(); | ||
| assertThatThrownBy(() -> client.unwrap().execute(reqCtx, req).aggregate().join()) |
There was a problem hiding this comment.
| 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 🤔
I guess ClientRequestContextBuilder().build() init cancellationScheduler immediately, but WebClient didn't.
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.
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.
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.
oh I tried to use Clients.newContextCaptor() but cancellationScheduler is still not init() by this way so ClientRequestContext.isTimedOut() return false 😅
jrhee17
left a comment
There was a problem hiding this comment.
Looks good overall! Left some minor comments 🙇
| .build(); | ||
|
|
||
| assertThat(reqCtx.isTimedOut()).isFalse(); | ||
| assertThatThrownBy(() -> client.unwrap().execute(reqCtx, req).aggregate().join()) |
There was a problem hiding this comment.
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.
Took another look at this PR.
The way I see it there are two options (or actually three):
- Use
log.responseCauseto determine whether a request/response has timed out (or actuallylog().getIfAvailable(RequestLogProperty.RESPONSE_CAUSE).responseCause();) - Modify
responseCancellationSchedulerso that either
1.initis 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! |
|
oh~ I'll update this PR on this weekend. thanks! :) |
084bf58 to
a8aa4a6
Compare
a8aa4a6 to
6c76245
Compare
jrhee17
left a comment
There was a problem hiding this comment.
Changes look good to me 👍 👍 👍
ikhoon
left a comment
There was a problem hiding this comment.
Thanks, @injae-kim! 🙇♂️🙇♂️
Related issue #4935
Motivation:
DnsTimeoutExceptionshould also settruetoctx.isTimedOut(). #4935, we found thatRequestContext.isTimedoutis 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.isTimedoutis set true well on DNS, session, write timeout tooDnsTimeoutExceptionshould also settruetoctx.isTimedOut(). #4935