[6.2.x] Fix TextMessage body thread safety (#2188)#2204
Merged
Conversation
This fixes the rare null body issues seen on the broker when using text messages by using synchronization when marshaling or unmarshaling the body into a String to prevent a race condition from causing the body to end up null. This has been optimized to use volatiles and double checked locking to avoid synchronization unless needed. (cherry picked from commit b131c3d)
Validates the fix for the race between getText(), storeContentAndClear() and copy() on a shared ActiveMQTextMessage instance that could null the message body: getText() decoded content into text and cleared content while storeContentAndClear() observed the pre-clear content, skipped re-encoding, and cleared text — losing the body permanently. Triggered on the broker by XPath selector evaluation or JMX browse racing dispatch marshalling, with the network bridge copy() adding a third participant. Four tests: - sequential control: getText/storeContentAndClear round trips preserve the body - two-way race: 20k iterations of concurrent getText vs storeContentAndClear; no iteration may lose the body - three-way race including copy(): both the original and the copy must retain a recoverable body (pre-fix this loses the original's body within a few thousand iterations) - deterministic lock-discipline pin: the fix serializes the text/content state transitions on the message instance, so storeContentAndClear() must block while another thread holds the message monitor; fails immediately on any regression to unsynchronized transitions Verified failing (2 of 4) against the pre-fix base and passing on this branch. Co-authored-by: Matt Pavlovich <mattrpav@apache.org> (cherry picked from commit e1368d5)
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.
This fixes the rare null body issues seen on the broker when using text messages by using synchronization when marshaling or unmarshaling the body into a String to prevent a race condition from causing the body to end up null. This has been optimized to use volatiles and double checked locking to avoid synchronization unless needed.
(cherry picked from commit b131c3d)