GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix concurrent chunk data write bug in adaptive allocator by chrisvest · Pull Request #15652 · netty/netty

Conversation

@chrisvest

@chrisvest chrisvest commented Sep 13, 2025

Copy link
Copy Markdown
Member

Motivation:
The adaptive allocator had a few code paths where the internal NIO buffer of the chunk got exposed and mutated directly, through methods like ByteBufUtil.writeUtf8 and .writeAscii. When such methods call internalNioBuffer, they mutate the position and limit of the shared internal buffer, which can lead to exceptions when other threads do the same concurrently.

Modification:
Add a flag to UnpooledDirectByteBuf which will prevent any sharing of the internalNioBuffer by throwing an exception. Use this to find and fix all cases in the AdaptiveByteBuf. Add a test that comprehensively tests this through ByteBuf.setCharSequence. This also proves that none of our other buffer implementations were affected.

Result:
ByteBuf.write/setCharSequence with the adaptive allocator can no longer corrupt data or cause random exceptions to be thrown, but may now be slightly slower as they have to allocate a ByteBuf-specific internal ByteBuffer if they don't already have one.

Fixes #15631

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

franz1981 and georgebanasios reacted with rocket emoji
All reactions
  • 🚀 2 reactions
@chrisvest
chrisvest requested review from franz1981 and normanmaurer September 13, 2025 02:03
@chrisvest
Fix concurrent chunk data write bug in adaptive allocator
b7ac318
Motivation:
The adaptive allocator had a few code paths where the internal NIO buffer of the chunk got exposed and mutated directly, through methods like ByteBufUtil.writeUtf8 and .writeAscii.
When such methods call internalNioBuffer, they mutate the position and limit of the shared internal buffer, which can lead to exceptions when other threads do the same concurrently.

Modification:
Add a flag to UnpooledDirectByteBuf which will prevent any sharing of the internalNioBuffer by throwing an exception.
Use this to find and fix all cases in the AdaptiveByteBuf.
Add a test that comprehensively tests this through ByteBuf.setCharSequence.
This also proves that none of our other buffer implementations were affected.

Result:
ByteBuf.write/setCharSequence with the adaptive allocator can no longer corrupt data or cause random exceptions to be thrown, but may now be slightly slower as they have to allocate a ByteBuf-specific internal ByteBuffer if they don't already have one.

Fixes netty#15631
@chrisvest
chrisvest force-pushed the 4.2-adaptive-setCharSequence branch from bb03edf to b7ac318 Compare September 13, 2025 02:05
@chrisvest chrisvest added this to the 4.2.7.Final milestone Sep 13, 2025
franz1981
franz1981 approved these changes Sep 13, 2025
View reviewed changes
normanmaurer
normanmaurer requested changes Sep 13, 2025
View reviewed changes
Comment thread buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest
Address review comments
e063049
normanmaurer
normanmaurer approved these changes Sep 15, 2025
View reviewed changes

@normanmaurer normanmaurer left a comment

Copy link
Copy Markdown
Member

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.

Great work!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@normanmaurer
normanmaurer merged commit 9352e4f into netty:4.2 Sep 15, 2025
@chrisvest
chrisvest deleted the 4.2-adaptive-setCharSequence branch September 15, 2025 17:43
normanmaurer pushed a commit that referenced this pull request Sep 16, 2025
@chrisvest @normanmaurer
Fix concurrent chunk data write bug in adaptive allocator (#15652)
888666f
Motivation:
The adaptive allocator had a few code paths where the internal NIO
buffer of the chunk got exposed and mutated directly, through methods
like ByteBufUtil.writeUtf8 and .writeAscii. When such methods call
internalNioBuffer, they mutate the position and limit of the shared
internal buffer, which can lead to exceptions when other threads do the
same concurrently.

Modification:
Add a flag to UnpooledDirectByteBuf which will prevent any sharing of
the internalNioBuffer by throwing an exception. Use this to find and fix
all cases in the AdaptiveByteBuf. Add a test that comprehensively tests
this through ByteBuf.setCharSequence. This also proves that none of our
other buffer implementations were affected.

Result:
ByteBuf.write/setCharSequence with the adaptive allocator can no longer
corrupt data or cause random exceptions to be thrown, but may now be
slightly slower as they have to allocate a ByteBuf-specific internal
ByteBuffer if they don't already have one.

Fixes #15631
normanmaurer added a commit that referenced this pull request Sep 16, 2025
@normanmaurer @chrisvest
Fix concurrent chunk data write bug in adaptive allocator (#15652) (#…
dc0c757
…15664)

Motivation:
The adaptive allocator had a few code paths where the internal NIO
buffer of the chunk got exposed and mutated directly, through methods
like ByteBufUtil.writeUtf8 and .writeAscii. When such methods call
internalNioBuffer, they mutate the position and limit of the shared
internal buffer, which can lead to exceptions when other threads do the
same concurrently.

Modification:
Add a flag to UnpooledDirectByteBuf which will prevent any sharing of
the internalNioBuffer by throwing an exception. Use this to find and fix
all cases in the AdaptiveByteBuf. Add a test that comprehensively tests
this through ByteBuf.setCharSequence. This also proves that none of our
other buffer implementations were affected.

Result:
ByteBuf.write/setCharSequence with the adaptive allocator can no longer
corrupt data or cause random exceptions to be thrown, but may now be
slightly slower as they have to allocate a ByteBuf-specific internal
ByteBuffer if they don't already have one.

Fixes #15631

Co-authored-by: Chris Vest <[email protected]>
This was referenced Sep 14, 2026
Http2: Reserve promised stream for PUSH_PROMISE after local RST_STREAM #17471
Closed
cache failure 1233e4a5 #17565
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer approved these changes
@franz1981 franz1981 franz1981 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.7.Final

Development

Successfully merging this pull request may close these issues.

io.netty.buffer.AdaptivePoolingAllocator throws java.lang.IndexOutOfBoundsException

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@chrisvest @normanmaurer @franz1981
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.