[
https://issues.apache.org/jira/browse/TUBEMQ-66?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17082788#comment-17082788
]
Guocheng Zhang commented on TUBEMQ-66:
--------------------------------------
After this modification, there will be problems in Flink-like usage scenarios:
after the reference count is changed to the boolean value, if the
TubeSingleSessionFactory object is initialized multiple times in the same
process, as long as there is a shutdown() call, then the other executing logics
in the same process will throw wrong infos.
> TubeSingleSessionFactory shutdown bug
> -------------------------------------
>
> Key: TUBEMQ-66
> URL: https://issues.apache.org/jira/browse/TUBEMQ-66
> Project: Apache TubeMQ
> Issue Type: Bug
> Reporter: Guo Jiwei
> Assignee: Guo Jiwei
> Priority: Normal
> Labels: pull-request-available
> Time Spent: 10m
> Remaining Estimate: 0h
>
> 1. TubeSingleSessionFactory could not shutdown
> due to we increase referenceCounter after first constructor method:
> {code:java}
> public TubeSingleSessionFactory(final TubeClientConfig tubeClientConfig)
> throws TubeClientException {
> if (referenceCounter.incrementAndGet() == 1) {
> RpcConfig config =
> TubeClientConfigUtils.getRpcConfigByClientConfig(tubeClientConfig, true);
> clientFactory.configure(config);
> //#1
> referenceCounter.incrementAndGet();
> baseSessionFactory = new TubeBaseSessionFactory(clientFactory,
> tubeClientConfig);
> }
> }
> {code}
> {code:java}
> public void shutdown() throws TubeClientException {
> if (referenceCounter.decrementAndGet() > 0) {
> return;
> }
> baseSessionFactory.shutdown();
> clientFactory.shutdown();
> }
> {code}
> We can fix it only remove #1, but I think this is not the best
> implementation for TubeSingleSessionFactory. How about do it like below :
> {code:java}
> private static final AtomicBoolean isStarted = new AtomicBoolean(false);
> private static TubeBaseSessionFactory baseSessionFactory;
> public TubeSingleSessionFactory(final TubeClientConfig tubeClientConfig)
> throws TubeClientException {
> if (isStarted.compareAndSet(false, true)) {
> RpcConfig config =
> TubeClientConfigUtils.getRpcConfigByClientConfig(tubeClientConfig, true);
> clientFactory.configure(config);
> baseSessionFactory = new TubeBaseSessionFactory(clientFactory,
> tubeClientConfig);
> }
> }
> @Override
> public void shutdown() throws TubeClientException {
> if (isStarted.compareAndSet(true, false)) {
> baseSessionFactory.shutdown();
> clientFactory.shutdown();
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)