Repository navigation
Handling error in creation of non-durable cursor - #7355
Merged
merlimat merged 2 commits intoJun 27, 2020
Merged
Conversation
merlimat
requested review from
codelipenghui,
ivankelly,
jerrypeng,
rdhabalia,
sijie and
srkukarni
June 24, 2020 23:59
codelipenghui
approved these changes
Jun 27, 2020
merlimat
added a commit
to merlimat/pulsar
that referenced
this pull request
Jun 30, 2020
codelipenghui
pushed a commit
to streamnative/pulsar-archived
that referenced
this pull request
Jul 14, 2020
* Handling error in creation of non-durable cursor * Fixed tests (cherry picked from commit 0a5f0a0)
cdbartholomew
pushed a commit
to kafkaesque-io/pulsar
that referenced
this pull request
Jul 21, 2020
* Handling error in creation of non-durable cursor * Fixed tests
cdbartholomew
pushed a commit
to kafkaesque-io/pulsar
that referenced
this pull request
Jul 24, 2020
* Handling error in creation of non-durable cursor * Fixed tests
wolfstudy
pushed a commit
that referenced
this pull request
Jul 29, 2020
* Handling error in creation of non-durable cursor * Fixed tests (cherry picked from commit 0a5f0a0)
huangdx0726
pushed a commit
to huangdx0726/pulsar
that referenced
this pull request
Aug 24, 2020
* Handling error in creation of non-durable cursor * Fixed tests
|
|
||
| synchronized (ledger) { | ||
| // Create a new non-durable cursor only for the first consumer that connects | ||
| Subscription subscription = subscriptions.computeIfAbsent(subscriptionName, name -> { |
Member
There was a problem hiding this comment.
@merlimat - I know this has been merged for a while, but I was reading through this class today, and I am concerned about a possible race condition that would lead to an incorrect update to the subscriptions map.
With this PR, the subscriptions map is no longer updated using the computeIfAbsent method here, but is instead modified with a get and then a subsequent put. The getDurableSubscription updates the subscriptions map concurrently as well. I believe this opens us up to a race under the following conditions:
- We call get for a subscription on line 695, and get
null. - Then, a durable subscription with the same name is added to the
subscriptionsmap on line 665. - Then, the non durable subscription is put into the
subscriptionsmap on new line 722, and in doing so, overwrites the durable subscription of the same name.
Do you agree this is a risk here? If so, I will work on contributing a fix. I wanted to check first though, just in case there is context I'm missing. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
We're getting an NPE when the creation of a non-durable cursor fails.
The reason is that, we fail the future but we go on in creating the subscription instance:
Additionally, the NPE leads to the topic usage count to not be decremented, leaking 1 usage increment. At the time of deletion, this will prevent the topic from being deleted, even when using the force flag.