Skip to content

Commit

Permalink
Fix a bug when client reconnect (#2135)
Browse files Browse the repository at this point in the history
* Add reconnection lock to control only one thread can can reconnect method.
This will avoid problem in this case:
Thread A reconnecting, and success, then send msg.
Thread B reconnecting but invoke disconnect. Then the Thread A will send msg fail because of Thread B's disconnecting call.

* fix sth
  • Loading branch information
carryxyh authored and zonghaishang committed Jul 26, 2018
1 parent ee7870c commit e90d95c
Showing 1 changed file with 11 additions and 2 deletions.
Expand Up @@ -321,8 +321,17 @@ public void disconnect() {

@Override
public void reconnect() throws RemotingException {
disconnect();
connect();
if (!isConnected()) {
connectLock.lock();
try {
if (!isConnected()) {
disconnect();
connect();
}
} finally {
connectLock.unlock();
}
}
}

@Override
Expand Down

0 comments on commit e90d95c

Please sign in to comment.