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

Use of CompositeByteBuf in NettyDataBuffer results in IllegalReferenceCountException [SPR-16351] #20898

spring-issuemaster opened this issue Jan 5, 2018 · 2 comments


None yet
2 participants
Copy link

commented Jan 5, 2018

Abhijit Sarkar opened SPR-16351 and commented

DataBuffer write(DataBuffer... buffers) is supposed to "Write one or more DataBuffers to this buffer, starting at the current writing position" but it doesn't.

Consider buffer = "abc", slice = "def" and buffer.writePosition() = 3. buffer.write(slice) is supposed to produce abcdef but instead buffer becomes abcabc. The workaround is to use the write overload that takes a byte[], like so:

DataBuffer slice = buffer.slice(startIdx, length);
byte[] slice1 = new byte[length];, 0, slice1.length);

Related to SO answer

Affects: 5.0.2

Reference URL:

Issue Links:

  • #20912 Using DataBuffer::write results in IndexOutOfBoundsException

Referenced from: commits 69ccba3, 8a129ef, e6893da


This comment has been minimized.

Copy link
Collaborator Author

commented Jan 10, 2018

Arjen Poutsma commented

Fixed, by removing use of CompositeByteBuf in NettyDataBuffer.write(ByteBuf...), see e6893da

As a consequence, DataBuffers fluxes that are aggregated with Flux.reduce(BiFunction) are now required to be released, as the composite no longer holds a
reference to subsequent data buffers. For this purpose, a write aggregator was introduced, see 69ccba3

In a final commit, we use the write aggregator throughout the Spring codebase: 8a129ef


This comment has been minimized.

Copy link
Collaborator Author

commented Jan 12, 2018

Arjen Poutsma commented

The writeAggregator() introduced above resulted in IndexOutOfBoundsException from Netty when merging the entire HTTP body. The solution is to use the newly introduced DataBufferUtils.compose method for merging multiple large buffers into one. See See #20912 for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.