Repository navigation
Fix Use-After-Release in CommandHandler.channelUnregistered() and close channel on channelRead() writeBytes failure #4030 - #4031
Open
juliojgd wants to merge 1 commit into
Conversation
…ered() and close channel on writeBytes failure redis#4030 We now null out readBuffer before releasing it in CommandHandler.channelUnregistered() so resetInternals() cannot call readBuffer.clear() on a ByteBuf already reclaimed by another EventLoop (e.g. under Netty 4.2 AdaptiveByteBufAllocator's shared MPMC recycler). We also close the channel if readBuffer.writeBytes(input) throws Throwable in CommandHandler.channelRead() so undecoded bytes cannot remain in readBuffer on an active channel and silently shift subsequent command responses. Closes redis#4030 Closes redis#4027
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Collaborator
|
Thanks for the reports. |
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.
Closes #4030
Closes #4027
Summary
This PR fixes two chained bugs in
io.lettuce.core.protocol.CommandHandlerthat together cause spontaneousIndexOutOfBoundsExceptionfollowed by silent cross-key response corruption under Netty 4.2's defaultAdaptiveByteBufAllocator:CommandHandler.channelUnregistered()(Use-After-Release in CommandHandler.channelUnregistered() under Netty 4.2 AdaptiveByteBufAllocator causes silent cross-key response corruption #4030):readBufferbefore releasing it and callingreset().readBuffer.release()returned the 64 KiBAdaptiveByteBufto Netty 4.2's shared cross-thread MPMC recycler while keepingthis.readBuffernon-null, allowingresetInternals()to callreadBuffer.clear()on a buffer already reclaimed by anotherEventLoop.CommandHandler.channelRead()(Read-side exception after buffer copy leaves channel active and shifts subsequent command responses #4027):readBuffer.writeBytes(input)withtry/catch (Throwable e) { ctx.close(); throw e; }(consistent withdecode(...)) so undecoded bytes cannot remain stranded inreadBufferon an active channel.Verification
CommandHandlerUnitTests:shouldNotClearReadBufferAfterReleaseInChannelUnregisteredshouldCloseChannelWhenWriteBytesThrowsInChannelReadmvn formatter:format/formatter:validate(0 formatting diffs) andCommandHandlerUnitTests+PubSubCommandHandlerUnitTests(50/50 passing).Checklist
mvn formatter:formattarget. Don’t submit any formatting related changes.Note
Medium Risk
Touches core Netty read/teardown paths in CommandHandler; changes are small and targeted but affect every Redis connection’s protocol handling.
Overview
Fixes two related bugs in
CommandHandleraround Netty 4.2’s aggressiveByteBufrecycling (#4030, #4027).In
channelUnregistered(),readBufferis nulled beforerelease(), soreset()→resetInternals()no longer callsclear()on a buffer that may already be reused on another event loop.In
channelRead(),readBuffer.writeBytes(input)is wrapped so any failure closes the channel and rethrows, matchingdecode()and avoiding undecoded bytes left on an open connection.Unit tests cover nulling after release and channel close when
writeBytesthrows.Reviewed by Cursor Bugbot for commit 952c57e. Bugbot is set up for automated code reviews on this repo. Configure here.