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
Conversation
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}.
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!
Codecov Report
@@ 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 Continue to review full report at Codecov.
|
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.
👍
…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}.
Motivation:
When creating a ContentPreviewerFactory withtout specifying
maxLength(...)
,A created ContentPreviewer from the factory will have zero
maxLength
.maxLength
makeslength
zero always in the ContentPreviewer.armeria/core/src/main/java/com/linecorp/armeria/common/logging/LengthLimitingContentPreviewer.java
Line 52 in e95e07b
length
could be set to 0 according to consumed content length.armeria/core/src/main/java/com/linecorp/armeria/common/logging/LengthLimitingContentPreviewer.java
Line 69 in e95e07b
If the
length
is equal to 0:retainedSlice(...)
will return an emptyByteBuf
.armeria/core/src/main/java/com/linecorp/armeria/common/logging/LengthLimitingContentPreviewer.java
Lines 78 to 88 in e95e07b
ByteBuf
is not readable.ByteBuf
be released unexpectedly when wrapped byUnpooled.wrappedBuffer(emptyBuf)
.https://github.com/netty/netty/blob/5a08dc0d9aeafe3b4e242e3b7722bfbd38acbbb2/buffer/src/main/java/io/netty/buffer/Unpooled.java#L317
ByteBuf
will cause anIllegalReferenceCountException
when it is consumed by
HttpResponseDecoder
Modifications:
Result:
You can not see
IllegalReferenceCountException
anymorewhen you log a preview content using ContentPreview{Client, Service}.