[ISSUE #S1] Scope the index list write lock to the list update in getAndCreateLastIndexFile - #11098
Open
zjncs wants to merge 1 commit into
Open
[ISSUE #S1] Scope the index list write lock to the list update in getAndCreateLastIndexFile#11098zjncs wants to merge 1 commit into
zjncs wants to merge 1 commit into
Conversation
…AndCreateLastIndexFile If IndexFile creation fails (e.g. the store directory is not writable), the catch block logs the error but the finally block then calls writeLock().unlock() although lock() was never reached, throwing IllegalMonitorStateException out of getAndCreateLastIndexFile into the message write path. Create the file outside the lock and only take the write lock to append it to indexFileList. Signed-off-by: zjncs <18910855655@163.com>
RockteMQ-AI
approved these changes
Sep 9, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Summary
Scopes the write lock to only guard the indexFileList.add() call, moving IndexFile construction outside the lock. This prevents IllegalMonitorStateException when file creation fails (the finally block was unlocking a lock that was never acquired). Well-structured fix with a targeted regression test.
LGTM.
Automated review by github-manager-bot
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
In
IndexService.getAndCreateLastIndexFilethe write lock is acquired inside thetryblock, after theIndexFileconstructor, whilefinallyunconditionally callswriteLock().unlock():When
IndexFilecreation fails (store directory missing/not writable/disk full), the constructor throws,lock()is never reached, and thefinallyblock throwsIllegalMonitorStateException, which propagates out ofgetAndCreateLastIndexFileintoputKeyEnd— i.e. into the message store write path (buildKey/putKeywhile appending index entries). The original creation failure is already logged; the extra IMSE only masks it.Modifications
IndexFileoutside the lock; take the write lock only to append it toindexFileList, with a balancedtry/finally.Verification
Fail-before (new test on unpatched code):
The test points the index store path below a regular file so
IndexFilecreation is guaranteed to fail.Pass-after — full
IndexServiceTest(5 existing + 1 new):