Skip to content

Set RequestContext.isTimedOut(true) on DNS, session, write timeout#5156

Merged
ikhoon merged 2 commits intoline:mainfrom
injae-kim:set-reqctx-istimedout-true
Aug 2, 2024
Merged

Set RequestContext.isTimedOut(true) on DNS, session, write timeout#5156
ikhoon merged 2 commits intoline:mainfrom
injae-kim:set-reqctx-istimedout-true

Conversation

@injae-kim
Copy link
Copy Markdown
Contributor

Related issue #4935

Motivation:

We need to make sure CancellationScheduler.finishNow(TimeoutException) is invoked on more timeout types,
such as session/connection/DNS timeout so that true is set to ctx.isTimedOut().

Modifications:

  • Set RequestContext.isTimedOut(true) on DNS, session, write timeout by ctx.cancel(TimeoutException.class)

Result:

@injae-kim injae-kim force-pushed the set-reqctx-istimedout-true branch from ae89c0b to 9396937 Compare August 29, 2023 14:42
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 29, 2023

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 29, 2023

Codecov Report

Attention: Patch coverage is 50.00000% with 13 lines in your changes missing coverage. Please review.

Project coverage is 73.92%. Comparing base (863e27c) to head (084bf58).
Report is 387 commits behind head on main.

Files Patch % Lines
...rmeria/client/SessionCreationTimeoutException.java 0.00% 10 Missing ⚠️
...ia/client/SessionProtocolNegotiationException.java 66.66% 1 Missing and 1 partial ⚠️
.../linecorp/armeria/client/ClientRequestContext.java 80.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

Comment thread core/src/main/java/com/linecorp/armeria/client/HttpClientDelegate.java Outdated
Comment thread core/src/main/java/com/linecorp/armeria/client/HttpChannelPool.java Outdated
Comment thread core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java Outdated
@injae-kim injae-kim force-pushed the set-reqctx-istimedout-true branch 2 times, most recently from 92426fb to d58b565 Compare September 1, 2023 08:04
.build();

assertThat(reqCtx.isTimedOut()).isFalse();
assertThatThrownBy(() -> client.unwrap().execute(reqCtx, req).aggregate().join())
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
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 🤔

responseCancellationScheduler.init(eventLoop(), noopCancellationTask, 0, /* server */ false);

I guess ClientRequestContextBuilder().build() init cancellationScheduler immediately, but WebClient didn't.

this.responseCancellationScheduler =
new CancellationScheduler(TimeUnit.MILLISECONDS.toNanos(responseTimeoutMillis));

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.

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 🙇

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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 😅

Copy link
Copy Markdown
Contributor

@jrhee17 jrhee17 left a 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 🙇

Comment thread core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java Outdated
.build();

assertThat(reqCtx.isTimedOut()).isFalse();
assertThatThrownBy(() -> client.unwrap().execute(reqCtx, req).aggregate().join())
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

@jrhee17 jrhee17 left a 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):

  1. Use log.responseCause to determine whether a request/response has timed out (or actually log().getIfAvailable(RequestLogProperty.RESPONSE_CAUSE).responseCause();)
  2. 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..) using ctx.cancellationScheduler.
    2. modify the behavior so that cancel() 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 🙇

@injae-kim
Copy link
Copy Markdown
Contributor Author

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~! 🙇

@minwoox
Copy link
Copy Markdown
Contributor

minwoox commented Oct 10, 2023

We have decided to go with the second option. @jrhee17 is laying the groundwork for that.
#5212
He will let you know when it's done. 😉

@injae-kim
Copy link
Copy Markdown
Contributor Author

We have decided to go with the second option

aha~ I checked #5212. thanks for sharing!
feel free to let me know when it's ready to go with the 2. option~! 🙇

@minwoox minwoox added this to the 1.27.0 milestone Oct 11, 2023
@ikhoon ikhoon modified the milestones: 1.27.0, 1.28.0 Jan 16, 2024
@minwoox
Copy link
Copy Markdown
Contributor

minwoox commented Apr 2, 2024

Since #5212 has been completed, perhaps we can resume this work now?
cc @jrhee17

@jrhee17 jrhee17 modified the milestones: 1.28.0, 1.29.0 Apr 2, 2024
@injae-kim
Copy link
Copy Markdown
Contributor Author

oh~ I'll update this PR on this weekend. thanks! :)

@github-actions github-actions Bot added the Stale label May 5, 2024
@minwoox minwoox modified the milestones: 1.29.0, 1.30.0 May 21, 2024
@github-actions github-actions Bot removed the Stale label May 23, 2024
@github-actions github-actions Bot added the Stale label Jun 22, 2024
@injae-kim injae-kim force-pushed the set-reqctx-istimedout-true branch from 084bf58 to a8aa4a6 Compare July 4, 2024 15:46
@injae-kim injae-kim force-pushed the set-reqctx-istimedout-true branch from a8aa4a6 to 6c76245 Compare July 4, 2024 15:54
@github-actions github-actions Bot removed the Stale label Jul 5, 2024
@injae-kim injae-kim requested a review from jrhee17 July 5, 2024 07:59
@injae-kim
Copy link
Copy Markdown
Contributor Author

Since #5212 has been completed, perhaps we can resume this work now?

@jrhee17, I updated this PR to latest based on #5212~! PTAL 🙇

Copy link
Copy Markdown
Contributor

@jrhee17 jrhee17 left a 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 👍 👍 👍

Copy link
Copy Markdown
Contributor

@minwoox minwoox left a 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! 😄

Copy link
Copy Markdown
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks, @injae-kim! 🙇‍♂️🙇‍♂️

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.

A DnsTimeoutException should also set true to ctx.isTimedOut().

4 participants