Skip to content

Commit

Permalink
[Broker] Fix race condition in stopping replicator while it is starting
Browse files Browse the repository at this point in the history
- there was a chance for a race condition that resulted in the replicator not disconnecting
  if disconnect was called when the replicator was starting.

upstream pull request apache#13412
  • Loading branch information
lhotari committed Dec 20, 2021
1 parent 85ddf12 commit a11da0f
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,13 @@ public synchronized CompletableFuture<Void> disconnect(boolean failIfHasBacklog)
return CompletableFuture.completedFuture(null);
}

if (producer != null && (STATE_UPDATER.compareAndSet(this, State.Starting, State.Stopping)
|| STATE_UPDATER.compareAndSet(this, State.Started, State.Stopping))) {
if (STATE_UPDATER.compareAndSet(this, State.Starting, State.Stopping)
|| STATE_UPDATER.compareAndSet(this, State.Started, State.Stopping)) {
log.info("[{}][{} -> {}] Disconnect replicator at position {} with backlog {}", topicName, localCluster,
remoteCluster, getReplicatorReadPosition(), getNumberOfEntriesInBacklog());
return closeProducerAsync();
}

STATE_UPDATER.set(this, State.Stopped);
return CompletableFuture.completedFuture(null);
return closeProducerAsync();
}

public CompletableFuture<Void> remove() {
Expand Down

0 comments on commit a11da0f

Please sign in to comment.