Skip to content

Conversation

@steviemo
Copy link
Contributor

No description provided.

@forresthopkinsa
Copy link
Contributor

There's a deeper problem here. It should be impossible for that set value to be null at that point, because it's taken directly from the map; the key it uses is taken from a keySet retrieved only three lines before.

For reference, this is the root of the problem in #82 :

Iterator<String> mapIterator = mEmitters.keySet().iterator();
    while (mapIterator.hasNext()) {
        String destinationUrl = mapIterator.next();
        Set<FlowableEmitter<? super StompMessage>> set = mEmitters.get(destinationUrl);
        // at this point, set is null

So, yeah, a null-check does fix the problem, but I'm concerned about the cause of the problem. There are only two ways that set could be null at that point:

  1. Somebody placed a null value in the map at that location

  2. That element of the map was removed somewhere between the retrieval of the keySet and the attempt to get it; a race condition

Now, considering that the only place in the code where items are added to the map looks like this:

if (emittersSet == null) {
    emittersSet = new HashSet<>();
    mEmitters.put(destinationPath, emittersSet);

... that rules out option 1. So, we're looking at a race condition. My guess is that you're running some sort of multithreaded operation that causes multiple topics to get unsubscribed at once, and from the looks of it, that part of the code wasn't really designed to handle concurrency.

So maybe we should change mEmitters to a ConcurrentHashMap? I'm not sure if that'll totally solve the problem, but I feel like it's a step in the right direction. What do you think?

@steviemo
Copy link
Contributor Author

Yep I agree I'll tweak the change the PR today.

@steviemo
Copy link
Contributor Author

PR updated @NaikSoftware @forresthopkinsa

@NaikSoftware NaikSoftware merged commit 885c8ce into NaikSoftware:master Oct 26, 2017
@forresthopkinsa
Copy link
Contributor

Awesome! Update us if you hit more concurrency problems. Thanks @steviemo !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants