-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[fix][broker] Return if AbstractDispatcherSingleActiveConsumer closed #19934
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that NonPersistentStickyKeyDispatcherMultipleConsumers
and PersistentStickyKeyDispatcherMultipleConsumers
also have the same problem, so we can fix them together?
Lines 86 to 95 in 55523ac
public synchronized void addConsumer(Consumer consumer) throws BrokerServiceException { | |
super.addConsumer(consumer); | |
try { | |
selector.addConsumer(consumer); | |
} catch (BrokerServiceException e) { | |
consumerSet.removeAll(consumer); | |
consumerList.remove(consumer); | |
throw e; | |
} | |
} |
Like the line 89 above, it should not be executed.
And could you write a test for these cases?
Good catch @poorbarcode , PTAL again |
Codecov Report
@@ Coverage Diff @@
## master #19934 +/- ##
=============================================
+ Coverage 24.42% 72.87% +48.44%
- Complexity 291 31615 +31324
=============================================
Files 1603 1861 +258
Lines 124343 137366 +13023
Branches 13571 15117 +1546
=============================================
+ Hits 30369 100101 +69732
+ Misses 89490 29323 -60167
- Partials 4484 7942 +3458
Flags with carried forward coverage won't be shown. Click here to find out more.
|
log.warn("[{}] Dispatcher is already closed. Closing consumer {}", name, consumer); | ||
consumer.disconnect(); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super.addConsumer(consumer)
already did this check, right? If yes, we should not repeatedly check it.
log.warn("[{}] Dispatcher is already closed. Closing consumer {}", name, consumer); | ||
consumer.disconnect(); | ||
return; | ||
} | ||
super.addConsumer(consumer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super.addConsumer(consumer)
already did this check, right? If yes, we should not repeatedly check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However the super.addConsumer
return value is void
. The method in subClass will not fast return if super.addConsumer
return. @poorbarcode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any other comments :) @poorbarcode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Technoboy- What do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, super.addConsumer(consumer)
can't fast return.
Consumer consumer = mock(Consumer.class); | ||
nonpersistentDispatcher.addConsumer(consumer); | ||
verify(consumer, times(1)).disconnect(); | ||
assertEquals(0, nonpersistentDispatcher.getConsumers().size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a verify: this consumer does not exist in the selector
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I will update it later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find that it's not easy to access the selector
, and verify assertEquals(0, nonpersistentDispatcher.getConsumers().size());
is enough. So maybe we needn't change it @poorbarcode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Consumer consumer = mock(Consumer.class); | ||
persistentDispatcher.addConsumer(consumer); | ||
verify(consumer, times(1)).disconnect(); | ||
assertEquals(0, persistentDispatcher.getConsumers().size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a verify: this consumer does not exist in the selector
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
As discussed on the mailing list https://lists.apache.org/thread/w4jzk27qhtosgsz7l9bmhf1t7o9mxjhp, there is no plan to release 2.9.6, so I am going to remove the release/2.9.6 label |
Motivation
We should disconect the consumer and return if
AbstractDispatcherSingleActiveConsumer
is closedModifications
Return after consumer disconnect
Verifying this change
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: AnonHxy#33