You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/02/12 01:37:50 UTC

[GitHub] [pulsar] sijie commented on a change in pull request #9565: [Broker] Fix race condition in BrokerService topic cache

sijie commented on a change in pull request #9565:
URL: https://github.com/apache/pulsar/pull/9565#discussion_r574943048



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java
##########
@@ -1005,4 +1003,33 @@ public void generate(SimpleTextOutputStream stream) {
         }
         Assert.assertTrue(sb.toString().contains("test_metrics"));
     }
+
+    @Test(timeOut = 20000L)
+    public void shouldNotPreventCreatingTopicWhenNonexistingTopicIsCached() throws Exception {
+        // run multiple iterations to increase the chance of reproducing a race condition in the topic cache
+        for (int i = 0; i < 100; i++) {
+            final String topicName = "persistent://prop/ns-abc/topic-caching-test-topic" + i;
+            CountDownLatch latch = new CountDownLatch(1);
+            Thread getStatsThread = new Thread(() -> {
+                try {
+                    latch.countDown();
+                    // create race condition with a short delay
+                    // the bug might not reproduce in all environments, this works at least on i7-10750H CPU
+                    Thread.sleep(1);
+                    admin.topics().getStats(topicName);
+                    fail("The topic should not exist yet.");
+                } catch (PulsarAdminException.NotFoundException e) {
+                    // expected exception
+                } catch (PulsarAdminException | InterruptedException e) {
+                    log.error("Exception in getStatsThread", e);

Review comment:
       Can you add the thread index in the error log message?

##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java
##########
@@ -1005,4 +1003,33 @@ public void generate(SimpleTextOutputStream stream) {
         }
         Assert.assertTrue(sb.toString().contains("test_metrics"));
     }
+
+    @Test(timeOut = 20000L)

Review comment:
       why do we need to add `timeOut` here?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org