Skip to content

Publish the destination paths only once they are complete - #2940

Merged
cshannon merged 1 commit into
apache:mainfrom
rzo1:destination-paths-race
Dec 4, 2026
Merged

cshannon merged 1 commit into
apache:mainfrom
rzo1:destination-paths-race

Conversation

@rzo1

@rzo1 rzo1 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #2939

ActiveMQDestination.getDestinationPaths() assigned the cached array to the field before filling it, so another thread calling it on the same instance could see null path elements. Over vm:// the broker parses the shared composite advisory topic of every connection, so two connections starting at the same moment could fail with a NullPointerException in DestinationMapNode.appendMatchingValues.

The paths are now filled into a local array and published through a volatile field.

ActiveMQDestinationPathsRaceTest (4 threads calling getDestinationPaths() on fresh destinations at the same moment, 20000 rounds) fails 3/3 without the change and passes 5/5 with it. activemq-client builds with all tests.

ActiveMQDestination.getDestinationPaths() assigned the cached array before
filling it, so another thread could see null path elements. Over vm:// the
broker parses the shared composite advisory topic of every connection, and
two connections starting at once failed with a NullPointerException in
DestinationMapNode. The paths are now filled into a local array and
published through a volatile field.

@cshannon cshannon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice catch

@cshannon cshannon self-assigned this Dec 4, 2026
@cshannon
cshannon merged commit bb147a7 into apache:main Dec 4, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Apache ActiveMQ v6.5.0 Dec 4, 2026
cshannon added a commit that referenced this pull request Dec 4, 2026
) (#2943)

ActiveMQDestination.getDestinationPaths() assigned the cached array before
filling it, so another thread could see null path elements. Over vm:// the
broker parses the shared composite advisory topic of every connection, and
two connections starting at once failed with a NullPointerException in
DestinationMapNode. The paths are now filled into a local array and
published through a volatile field.

(cherry picked from commit bb147a7)

Co-authored-by: Richard Zowalla <13417392+rzo1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ActiveMQDestination.getDestinationPaths() publishes a partially filled array to other threads

2 participants