Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #571: ConcurrentModificationException in MemorySubscriptionsRepository #572

Conversation

hylkevds
Copy link
Collaborator

@hylkevds hylkevds commented Feb 2, 2021

The MemorySubscriptionsRepository implementation does not synchronise
write access to the subscriptions list. As a result, Iterations over the
list will break when another Thread modifies the list.
This changes the ArrayList to a ConcurrentSkipListSet and changes the
interface of the public List listAllSubscriptions() method
to return a Set.

…riptionsRepository

The MemorySubscriptionsRepository implementation does not synchronise
write access to the subscriptions list. As a result, Iterations over the
list will break when another Thread modifies the list.
This changes the ArrayList to a ConcurrentSkipListSet and changes the
interface of the public List<Subscription> listAllSubscriptions() method
to return a Set.
Copy link
Collaborator

@andsel andsel left a comment

Choose a reason for hiding this comment

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

Hi @hylkevds I've create #595 to switch to Topic and Subscription to be comparable.
Check if you want that PR goes before on master on embed into this one


public class MemorySubscriptionsRepository implements ISubscriptionsRepository {

private final List<Subscription> subscriptions = new ArrayList<>();
private final Set<Subscription> subscriptions = new ConcurrentSkipListSet<>((o1, o2) -> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of providing an explicit comparator is better to implements the Comparable interface, PR for the change is #595

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, totally agree. Only reason I didn't was to minimise the impact of the PR.
After merging #595, I can either update this PR, or you merge it and then fix the constructor to not supply a Comparator.

@andsel andsel merged commit 055031d into moquette-io:master May 2, 2021
@andsel andsel added the v0.15.0 label May 8, 2021
@hylkevds hylkevds deleted the fix_571_CME_MemorySubscriptionsRepository branch May 9, 2021 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants