Skip to content

Commit

Permalink
Use synchronized when accessing consumers identity map (apache#3540)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlimat authored Feb 7, 2019
1 parent 3a5df1a commit 1e531e0
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,13 @@ public CompletableFuture<List<String>> getPartitionsForTopic(String topic) {

@SuppressWarnings("unchecked")
private <T> Optional<ConsumerBase<T>> subscriptionExist(ConsumerConfigurationData<?> conf) {
Optional<ConsumerBase<?>> subscriber = consumers.keySet().stream()
.filter(consumerBase -> consumerBase.getSubType().equals(PulsarApi.CommandSubscribe.SubType.Shared))
.filter(c -> c.getSubscription().equals(conf.getSubscriptionName()))
.findFirst();
return subscriber.map(ConsumerBase.class::cast);
synchronized (consumers) {
Optional<ConsumerBase<?>> subscriber = consumers.keySet().stream()
.filter(consumerBase -> consumerBase.getSubType().equals(PulsarApi.CommandSubscribe.SubType.Shared))
.filter(c -> c.getSubscription().equals(conf.getSubscriptionName()))
.findFirst();
return subscriber.map(ConsumerBase.class::cast);
}
}

private static EventLoopGroup getEventLoopGroup(ClientConfigurationData conf) {
Expand Down

0 comments on commit 1e531e0

Please sign in to comment.