Skip to content

Commit

Permalink
ZOOKEEPER-3652: Synchronize ClientCnxn outgoing queue flush on a stab…
Browse files Browse the repository at this point in the history
…le internal value

When packets are added to ClientCnxn's outgoing packet queue we ensure there's no conflict with an ongoing flush of that queue because of connection loss.

Synchronization used to be on the state field's value. This value is both not stable (its value changes over time), possibly causing improper synchronization, and global, which can cause contention in applications that run several ZooKeeper clients.

We now synchronize on outgoingQueue which is both local to a ClientCnxn's instance and stable.
  • Loading branch information
swallez committed Mar 29, 2022
1 parent d7cb4e8 commit b0bc03d
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ public void run() {
}
}

synchronized (state) {
synchronized (outgoingQueue) {
// When it comes to this point, it guarantees that later queued
// packet to outgoingQueue will be notified of death.
cleanup();
Expand Down Expand Up @@ -1671,7 +1671,7 @@ public Packet queuePacket(
// 1. synchronize with the final cleanup() in SendThread.run() to avoid race
// 2. synchronized against each packet. So if a closeSession packet is added,
// later packet will be notified.
synchronized (state) {
synchronized (outgoingQueue) {
if (!state.isAlive() || closing) {
conLossPacket(packet);
} else {
Expand Down

0 comments on commit b0bc03d

Please sign in to comment.