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

Fix a bug where ContentPreviewer unexpectly releases an HttpData #2905

Merged
merged 1 commit into from Jul 17, 2020

Conversation

ikhoon
Copy link
Contributor

@ikhoon ikhoon commented Jul 17, 2020

Motivation:

When creating a ContentPreviewerFactory withtout specifying maxLength(...),
A created ContentPreviewer from the factory will have zero maxLength.

ContentPreviewerFactory factory =
    ContentPreviewerFactory.builder()
                            .text((unused1, unused2) -> true)
                            .build();

If the length is equal to 0:

Modifications:

  • Set the default value of the max length of content preview to 32.
  • Do not duplicate if preview content length is 0

Result:

You can not see IllegalReferenceCountException anymore
when you log a preview content using ContentPreview{Client, Service}.

Motivation:

When creating a ContentPreviewerFactory withtout specifying `maxLength(...)`,
A created ContentPreviewer from the factory will have zero `maxLength`.
```java
ContentPreviewerFactory factory =
    ContentPreviewerFactory.builder()
                            .text((unused1, unused2) -> true)
                            .build();
```
The zero `maxLength` makes `length` zero always.
And also `length` could be set to 0 according to consumed content length.

If the `length` is equal to 0:
- `retainedSlice(...)` will return an empty `ByteBuf`.
   https://github.com/line/armeria/blob/e95e07b528092d90566281dac7673a71305a2705/core/src/main/java/com/linecorp/armeria/common/logging/LengthLimitingContentPreviewer.java#L78-L88
- The empty `ByteBuf` is not readable.
- The unreadable `ByteBuf` be released unexpectedly when wrapped by `Unpooled.wrappedBuffer(emptyBuf)`.
  https://github.com/netty/netty/blob/5a08dc0d9aeafe3b4e242e3b7722bfbd38acbbb2/buffer/src/main/java/io/netty/buffer/Unpooled.java#L317
- The release `ByteBuf` will cause an `IllegalReferenceCountException`
  when it is consumed by `HttpResponseDecoder`

Modifications:

- Set the default value of max length of content preview to 32.
- Do not duplicate if preview content length is 0

Result:

You can not see `IllegalReferenceCountException` anymore
when you log a preview content using ContentPreview{Client, Service}.
@ikhoon ikhoon added the defect label Jul 17, 2020
@ikhoon ikhoon added this to the 0.99.9 milestone Jul 17, 2020
Copy link
Member

@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.

Thanks!

@codecov
Copy link

codecov bot commented Jul 17, 2020

Codecov Report

Merging #2905 into master will increase coverage by 0.01%.
The diff coverage is 69.56%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2905      +/-   ##
============================================
+ Coverage     72.88%   72.90%   +0.01%     
- Complexity    12179    12190      +11     
============================================
  Files          1069     1070       +1     
  Lines         47389    47408      +19     
  Branches       5944     5947       +3     
============================================
+ Hits          34541    34561      +20     
- Misses         9819     9821       +2     
+ Partials       3029     3026       -3     
Impacted Files Coverage Δ Complexity Δ
...armeria/server/AnnotatedServiceBindingBuilder.java 77.77% <0.00%> (-2.56%) 15.00 <0.00> (ø)
.../linecorp/armeria/server/ServiceConfigBuilder.java 63.88% <0.00%> (-1.83%) 13.00 <0.00> (ø)
...ver/VirtualHostAnnotatedServiceBindingBuilder.java 60.31% <0.00%> (-1.98%) 11.00 <0.00> (ø)
...meria/server/VirtualHostServiceBindingBuilder.java 41.46% <0.00%> (-1.04%) 13.00 <0.00> (ø)
...common/logging/LengthLimitingContentPreviewer.java 93.75% <75.00%> (-3.03%) 14.00 <0.00> (+1.00) ⬇️
...ain/java/com/linecorp/armeria/client/Endpoint.java 90.78% <100.00%> (+0.24%) 84.00 <2.00> (+2.00)
...common/logging/ContentPreviewerFactoryBuilder.java 71.05% <100.00%> (+8.89%) 14.00 <0.00> (+1.00)
.../armeria/server/AbstractServiceBindingBuilder.java 96.42% <100.00%> (+0.27%) 12.00 <1.00> (+1.00)
...linecorp/armeria/server/ServiceBindingBuilder.java 78.04% <100.00%> (+0.54%) 28.00 <1.00> (+1.00)
.../linecorp/armeria/server/ServiceConfigSetters.java 100.00% <100.00%> (ø) 2.00 <2.00> (?)
... and 11 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 9895168...2777c0a. Read the comment docs.

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.

👍

@trustin trustin merged commit c8d1611 into line:master Jul 17, 2020
@ikhoon ikhoon deleted the content-preview-empty-length branch July 23, 2020 05:13
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
…e#2905)

Motivation:

When creating a ContentPreviewerFactory withtout specifying `maxLength(...)`,
A created ContentPreviewer from the factory will have zero `maxLength`.
```java
ContentPreviewerFactory factory =
    ContentPreviewerFactory.builder()
                            .text((unused1, unused2) -> true)
                            .build();
```
- The zero `maxLength` makes `length` zero always in the ContentPreviewer.
https://github.com/line/armeria/blob/e95e07b528092d90566281dac7673a71305a2705/core/src/main/java/com/linecorp/armeria/common/logging/LengthLimitingContentPreviewer.java#L52
- And also `length` could be set to 0 according to consumed content length.
https://github.com/line/armeria/blob/e95e07b528092d90566281dac7673a71305a2705/core/src/main/java/com/linecorp/armeria/common/logging/LengthLimitingContentPreviewer.java#L69

If the `length` is equal to 0:
- `retainedSlice(...)` will return an empty `ByteBuf`.
   https://github.com/line/armeria/blob/e95e07b528092d90566281dac7673a71305a2705/core/src/main/java/com/linecorp/armeria/common/logging/LengthLimitingContentPreviewer.java#L78-L88
- The empty `ByteBuf` is not readable.
- The unreadable `ByteBuf` be released unexpectedly when wrapped by `Unpooled.wrappedBuffer(emptyBuf)`.
  https://github.com/netty/netty/blob/5a08dc0d9aeafe3b4e242e3b7722bfbd38acbbb2/buffer/src/main/java/io/netty/buffer/Unpooled.java#L317
- The released `ByteBuf` will cause an `IllegalReferenceCountException`
  when it is consumed by `HttpResponseDecoder`

Modifications:

- Set the default value of the max length of content preview to 32.
- Do not duplicate if preview content length is 0

Result:

You can not see `IllegalReferenceCountException` anymore
when you log a preview content using ContentPreview{Client, Service}.
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.

None yet

3 participants