diff --git a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/DistributedHerder.java b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/DistributedHerder.java index 86e9e81853f76..e59025dd50497 100644 --- a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/DistributedHerder.java +++ b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/DistributedHerder.java @@ -316,8 +316,13 @@ public void tick() { try { // if we failed to read to end of log before, we need to make sure the issue was resolved before joining group // Joining and immediately leaving for failure to read configs is exceedingly impolite - if (!canReadConfigs && !readConfigToEnd(workerSyncTimeoutMs)) - return; // Safe to return and tick immediately because readConfigToEnd will do the backoff for us + if (!canReadConfigs) { + if (readConfigToEnd(workerSyncTimeoutMs)) { + canReadConfigs = true; + } else { + return; // Safe to return and tick immediately because readConfigToEnd will do the backoff for us + } + } log.debug("Ensuring group membership is still active"); member.ensureActive(); @@ -1105,7 +1110,9 @@ private boolean handleRebalanceCompleted() { // we timed out. This should only happen if we failed to read configuration for long enough, // in which case giving back control to the main loop will prevent hanging around indefinitely after getting kicked out of the group. // We also indicate to the main loop that we failed to readConfigs so it will check that the issue was resolved before trying to join the group - if (!readConfigToEnd(workerSyncTimeoutMs)) { + if (readConfigToEnd(workerSyncTimeoutMs)) { + canReadConfigs = true; + } else { canReadConfigs = false; needsRejoin = true; } diff --git a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/DistributedHerderTest.java b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/DistributedHerderTest.java index 570f398c6b090..8cf485ac9fa9f 100644 --- a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/DistributedHerderTest.java +++ b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/distributed/DistributedHerderTest.java @@ -1668,6 +1668,11 @@ public Boolean answer() throws Throwable { member.poll(EasyMock.anyInt()); PowerMock.expectLastCall(); + // one more tick, to make sure we don't keep trying to read to the config topic unnecessarily + expectRebalance(1, Collections.emptyList(), Collections.emptyList()); + member.poll(EasyMock.anyInt()); + PowerMock.expectLastCall(); + PowerMock.replayAll(); long before = time.milliseconds(); @@ -1685,6 +1690,10 @@ public Boolean answer() throws Throwable { time.sleep(2000L); assertStatistics("leaderUrl", false, 3, 1, 100, 2000L); + // tick once more to ensure that the successful read to the end of the config topic was + // tracked and no further unnecessary attempts were made + herder.tick(); + PowerMock.verifyAll(); }