kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject kafka git commit: MINOR: Fix potential deadlock in consumer close test
Date Mon, 03 Apr 2017 11:58:21 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 3364f12bc -> 1ba8b40b3


MINOR: Fix potential deadlock in consumer close test

Fixes deadlock scenario found during local test run:
The main thread was waiting for the coordinator lock.
The thread performing close() was holding the
coordinator lock and polling to find coordinator.
The test expected close() to timeout, but for timing
out, the main thread had to update time, which it
couldn't since it was waiting for the lock. This fix
avoids using coordinator in the main thread during
the close task.

Author: Rajini Sivaram <rajinisivaram@googlemail.com>

Reviewers: Ismael Juma <ismael@juma.me.uk>

Closes #2792 from rajinisivaram/MINOR-closetest-deadlock


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/1ba8b40b
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/1ba8b40b
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/1ba8b40b

Branch: refs/heads/trunk
Commit: 1ba8b40b3421ad0d23787ba9a1a4b635d8f11d91
Parents: 3364f12
Author: Rajini Sivaram <rajinisivaram@googlemail.com>
Authored: Mon Apr 3 12:57:34 2017 +0100
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Mon Apr 3 12:57:40 2017 +0100

----------------------------------------------------------------------
 .../clients/consumer/internals/ConsumerCoordinatorTest.java     | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/1ba8b40b/clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerCoordinatorTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerCoordinatorTest.java
b/clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerCoordinatorTest.java
index f0b289f..2a1f368 100644
--- a/clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerCoordinatorTest.java
+++ b/clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerCoordinatorTest.java
@@ -1526,6 +1526,9 @@ public class ConsumerCoordinatorTest {
             long expectedMinTimeMs, long expectedMaxTimeMs) throws Exception {
         ExecutorService executor = Executors.newSingleThreadExecutor();
         try {
+            boolean coordinatorUnknown = coordinator.coordinatorUnknown();
+            // Run close on a different thread. Coordinator is locked by this thread, so
it is
+            // not safe to use the coordinator from the main thread until the task completes.
             Future<?> future = executor.submit(new Runnable() {
                 @Override
                 public void run() {
@@ -1534,7 +1537,7 @@ public class ConsumerCoordinatorTest {
             });
             // Wait for close to start. If coordinator is known, wait for close to queue
             // at least one request. Otherwise, sleep for a short time.
-            if (!coordinator.coordinatorUnknown())
+            if (!coordinatorUnknown)
                 client.waitForRequests(1, 1000);
             else
                 Thread.sleep(200);


Mime
View raw message