Skip to content

Fix AMQP race condition with concurrent dispatch and copy of messages #1858

@cshannon

Description

@cshannon

As discussed in detail in #1851, there is a race condition with AMQP where text messages that are published to a topic can be delivered with a null body when sent over a network bridge and local consumer.

The root cause is the that ActiveMQTextMessage can be mutated during copy and marshaling which can lead the the body becoming null as the message is optimized to only store the data in one format (binary or String). The messages are not supposed to be accessed by multiple threads and copied first, but with topics this can be violated to avoid having a ton of copies in memory and can lead to the issue.

The long term solution is to improve the thread safety of either the messages or how the messages are used in the broker. This a longer term goal and there will be a follow on issue to discuss and implement improvements.

The short term solution as a quick fix is to ensure the AMQP protocol converter marshals the message before passing it along to the broker. This brings the behavior inline with OpenWire (non VM at least) because the message will be already marshaled so when the broker later goes to make copies or sends to consumers there won't be an issue as no mutation will be attempted as the data is already marshaled.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions