Skip to content
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

Correctly throw WriteTimeoutException for requests without content #4259

Merged
merged 1 commit into from
Jun 1, 2022

Conversation

jrhee17
Copy link
Contributor

@jrhee17 jrhee17 commented May 18, 2022

Motivation:

WriteTimeoutException is defined as an exception thrown if the first message write doesn't complete within a specified time. This specification holds for requests with bodies.

However, requests without bodies never throw a WriteTimeoutException because:

  1. Requests without bodies complete their stream immediately

subscriber.onSubscribe(this);
final Throwable abortCause = this.abortCause;
if (abortCause != null) {
onError(abortCause);
} else if (isEmpty()) {
onComplete();
}

  1. This in turn, cancels the write timeout immediately

Modifications:

  • Remove the call to HttpRequestSubscriber#cancelTimeout when the subscription on the request is complete.

Result:

Verified the following test passes:
https://github.com/jrhee17/armeria/blob/13c2c60e60b6109531b363d55d09ab6af7de432c/core/src/test/java/com/linecorp/armeria/client/TimeoutTest.java

Also created a PR which helps simulate slow writes as a follow-up:
#4260

@codecov
Copy link

codecov bot commented May 18, 2022

Codecov Report

Merging #4259 (624ad6c) into master (5a2c720) will decrease coverage by 0.01%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##             master    #4259      +/-   ##
============================================
- Coverage     73.38%   73.37%   -0.02%     
+ Complexity    16985    16982       -3     
============================================
  Files          1451     1451              
  Lines         64034    64033       -1     
  Branches       8039     8039              
============================================
- Hits          46994    46983      -11     
- Misses        12952    12953       +1     
- Partials       4088     4097       +9     
Impacted Files Coverage Δ
...linecorp/armeria/client/HttpRequestSubscriber.java 66.03% <ø> (-0.22%) ⬇️
...ecorp/armeria/server/LengthBasedServiceNaming.java 75.00% <0.00%> (-16.67%) ⬇️
...armeria/internal/common/stream/SubscriberUtil.java 72.22% <0.00%> (-11.12%) ⬇️
...eria/internal/common/stream/StreamMessageUtil.java 61.11% <0.00%> (-5.56%) ⬇️
...ia/common/stream/ConcatPublisherStreamMessage.java 78.29% <0.00%> (-3.88%) ⬇️
...rmeria/common/stream/ConcatArrayStreamMessage.java 82.22% <0.00%> (-2.23%) ⬇️
...p/armeria/common/stream/FuseableStreamMessage.java 81.36% <0.00%> (-1.87%) ⬇️
.../linecorp/armeria/client/Http1ResponseDecoder.java 56.97% <0.00%> (-0.59%) ⬇️
...corp/armeria/common/logging/DefaultRequestLog.java 79.72% <0.00%> (-0.26%) ⬇️
...com/linecorp/armeria/server/HttpServerHandler.java 80.57% <0.00%> (+0.35%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a2c720...624ad6c. Read the comment docs.

@jrhee17 jrhee17 changed the title Correctly thrown WriteTimeoutException for requests without content Correctly throw WriteTimeoutException for requests without content May 18, 2022
@jrhee17 jrhee17 added the defect label May 18, 2022
@jrhee17 jrhee17 added this to the 1.17.0 milestone May 18, 2022
@jrhee17 jrhee17 marked this pull request as ready for review May 18, 2022 08:33
Copy link
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 for the quick fix. 🙇‍♂️

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this. I wish we can add a test for it soon.

@trustin trustin merged commit f777f14 into line:master Jun 1, 2022
minwoox pushed a commit that referenced this pull request Jul 5, 2022
Motivation:

- Currently, there is no easy way to create integration tests which simulate certain behaviors (e.g. `WriteTimeoutException`) 
    - #4259 
- Users may also want to customize behavior like throttling, fault injection, etc. for clients.

Modifications:

- Add `CHANNEL_PIPELINE_CUSTOMIZER` to `ClientFactoryOptions`, which is a consumer on `ChannelPipeline`
    - I'm a little skeptical of adding these methods to `ClientFactoryBuilder`, `Flags` until more users want this feature.
- Call `HttpClientFactory#channelPipelineCustomizer` right before `channel#connect`, giving users to customize the pipeline at the last minute.
- Add a unit test which simulates write timeout behavior.
- Rename `invokeProxyConnectFailed` to `maybeHandleProxyFailure` to better represent what the method is doing.

Result:

- Closes #3907
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WriteTimeoutException may not be thrown for header-only requests
3 participants