Do not fail when compressing empty HttpContent#13655
Merged
normanmaurer merged 2 commits intonetty:4.1from Oct 10, 2023
Merged
Conversation
Motivation: HttpContentCompressor fails with an exception when trying to write an empty HttpContent: ``` io.netty.handler.codec.EncoderException: MessageToMessageCodec$1 must produce at least one message. at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:99) at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:879) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:863) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:968) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:856) at io.netty.channel.ChannelDuplexHandler.write(ChannelDuplexHandler.java:115) ``` Modification: If the compression has no output, write an empty dummy HttpContent. This is not an ideal solution, but this should not happen often anyway. Result: HttpContentCompressor does not fail anymore.
normanmaurer
requested changes
Oct 9, 2023
| state = State.AWAIT_HEADERS; | ||
| } else if (out.isEmpty()) { | ||
| // MessageToMessageCodec needs at least one output message | ||
| out.add(new DefaultHttpContent(Unpooled.EMPTY_BUFFER)); |
Member
There was a problem hiding this comment.
I think we should better move this to encodeContent WDYT ?
Contributor
Author
There was a problem hiding this comment.
sorry didn't have time to try this yesterday.
I think it makes more sense to have this in encode. It's only necessary if no further items are added after the call to encodeContent, and in encode, it's more clear that this is the case. In both branches where encodeContent is called (AWAIT_CONTENT and AWAIT_HEADERS + FullHttpResponse) it turns out that encodeContent is only called once and is the last one to add to out as well, so moving the patch would work, but imo this is much harder to see so the check makes more sense in encode.
…ntCompressorTest.java Co-authored-by: Norman Maurer <norman_maurer@apple.com>
normanmaurer
added a commit
that referenced
this pull request
Oct 11, 2023
Motivation: HttpContentCompressor fails with an exception when trying to write an empty HttpContent: ``` io.netty.handler.codec.EncoderException: MessageToMessageCodec$1 must produce at least one message. at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:99) at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:879) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:863) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:968) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:856) at io.netty.channel.ChannelDuplexHandler.write(ChannelDuplexHandler.java:115) ``` Modification: If the compression has no output, write an empty dummy HttpContent. This is not an ideal solution, but this should not happen often anyway. Result: HttpContentCompressor does not fail anymore. --------- Co-authored-by: Norman Maurer <norman_maurer@apple.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
HttpContentCompressor fails with an exception when trying to write an empty HttpContent:
Modification:
If the compression has no output, write an empty dummy HttpContent. This is not an ideal solution, but this should not happen often anyway.
Result:
HttpContentCompressor does not fail anymore.