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

Sending DefaultLastContent with trailers causes "io.netty.handler.codec.EncoderException: HttpServerCodec$HttpServerResponseEncoder must produce at least one message." #7418

Closed
pkolaczk opened this issue Nov 18, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@pkolaczk
Copy link
Contributor

Expected behavior

Writing DefaultLastContent object with trailing headers sends an empty chunk with trailing headers.

Actual behavior

Writing DefaultLastContent with trailing headers causes EncoderException:

io.netty.handler.codec.EncoderException: HttpServerCodec$HttpServerResponseEncoder must produce at least one message.
        at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:98) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.CombinedChannelDuplexHandler.write(CombinedChannelDuplexHandler.java:348) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:732) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:724) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:809) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:717) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.handler.logging.LoggingHandler.write(LoggingHandler.java:254) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:732) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:795) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:807) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:788) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:824) ~[netty-all-4.0.52.Final.jar:4.0.52.Final]
        at com.datastax.bdp.fs.rest.util.NettyHttpUtil$.writeAndFlush(NettyHttpUtil.scala:77) ~[dse-dsefs-common-5.0.12-cbbffcf.jar:5.0.12-cbbffcf]
        at com.datastax.bdp.fs.rest.server.RestServerHandler$$anonfun$sendResponseBody$2.apply(RestServerHandler.scala:163) [dse-dsefs-common-5.0.12-cbbffcf.jar:5.0.12-cbbffcf]
        at com.datastax.bdp.fs.rest.server.RestServerHandler$$anonfun$sendResponseBody$2.apply(RestServerHandler.scala:143) [dse-dsefs-common-5.0.12-cbbffcf.jar:5.0.12-cbbffcf]
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.10.6.jar:na]
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:399) [netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:464) [netty-all-4.0.52.Final.jar:4.0.52.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:131) [netty-all-4.0.52.Final.jar:4.0.52.Final]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]

Writing DefaultLastContent with no trailing headers in the same place of code, works as expected - sends an empty last chunk and no exception is thrown.

Steps to reproduce

  1. Setup a simple HttpServer using HttpServerCodec (without HttpMessageAggregator)
  2. When sending a response, enable chunked transfer encoding.
  3. writeAndFlush a DefaultLastContent object with trailers:
   val lastContent = new DefaultLastHttpContent()
   lastContent.trailingHeaders().add(...., ....)
   context.writeAndFlush(lastContent)

Minimal yet complete reproducer code (or URL to code)

Netty version

We found the problem after upgrading to 4.0.52.Final
Error was not present in 4.0.34.Final.

JVM version (e.g. java -version)

java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

OS version (e.g. uname -a)

Linux p5520 4.14.0-041400rc8-generic #201711052313 SMP Sun Nov 5 23:14:08 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

@normanmaurer
Copy link
Member

normanmaurer commented Nov 19, 2017 via email

normanmaurer added a commit that referenced this issue Nov 19, 2017
Motivation:

#7418 reported an issue with writing a LastHttpContent with trailers set.

Modifications:

Add unit test to ensure this issue is fixed in latest netty release.

Result:

Ensure code is correct.
normanmaurer added a commit that referenced this issue Nov 19, 2017
Motivation:

4732fab introduced a regression in HttpObjectEncoder which will lead to buffer leak and IllegalStateException when a LastHttpContent with trailers is written.

Modifications:

- Correctly add the buffer to the encoded list.
- Add testcases

Result:

Fixes [#7418]
normanmaurer added a commit that referenced this issue Nov 21, 2017
Motivation:

#7418 reported an issue with writing a LastHttpContent with trailers set.

Modifications:

Add unit test to ensure this issue is fixed in latest netty release.

Result:

Ensure code is correct.
normanmaurer added a commit that referenced this issue Nov 21, 2017
Motivation:

4732fab introduced a regression in HttpObjectEncoder which will lead to buffer leak and IllegalStateException when a LastHttpContent with trailers is written.

Modifications:

- Correctly add the buffer to the encoded list.
- Add testcases

Result:

Fixes [#7418]
@normanmaurer
Copy link
Member

Fixed by
8009c4c

@normanmaurer normanmaurer self-assigned this Nov 21, 2017
@normanmaurer normanmaurer added this to the 4.0.54.Final milestone Nov 21, 2017
kiril-me pushed a commit to kiril-me/netty that referenced this issue Feb 28, 2018
Motivation:

netty#7418 reported an issue with writing a LastHttpContent with trailers set.

Modifications:

Add unit test to ensure this issue is fixed in latest netty release.

Result:

Ensure code is correct.
pulllock pushed a commit to pulllock/netty that referenced this issue Oct 19, 2023
Motivation:

4732fab introduced a regression in HttpObjectEncoder which will lead to buffer leak and IllegalStateException when a LastHttpContent with trailers is written.

Modifications:

- Correctly add the buffer to the encoded list.
- Add testcases

Result:

Fixes [netty#7418]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants