Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Fix thread safety in SubscriptionManager #1540

Merged

Conversation

ajsutton
Copy link
Contributor

PR description

SubscriptionManager was using to HashMap instances to track subscription data which isn't thread safe. While subscribe and unsubscribe actions happen on the single vertx event loop thread, retrieving subscriptions and sending messages could happen from any thread depending on which thread notifies of the event (or because notifySubscribersOnWorkerThread was used).

Fix is to move the connection ID into the Subscription instance so we have a single object containing all the relevant data and can use a single map. That map can then be a ConcurrentHashMap to ensure that it can be iterated safely while updates may happen on other threads.

Connection ID is now tracked as a property of the subscription rather than as a separate map, so we can use a single concurrent map to track all details of subscriptions.
Copy link
Contributor

@lucassaldanha lucassaldanha left a comment

Choose a reason for hiding this comment

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

LGTM.

@lucassaldanha lucassaldanha merged commit 0f1162d into PegaSysEng:master Jun 10, 2019
@ajsutton ajsutton deleted the subscription-manager-threading branch June 10, 2019 02:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants