lhotari opened a new issue #9564:
URL: https://github.com/apache/pulsar/issues/9564


   **Describe the bug**
   Topic auto-creation fails due to a race condition. This seems to happen to 
be one of the issues causing flakiness in PulsarFunctionLocalRunTest, reported 
as #8720 .
   
   **To Reproduce**
   ```
       @Test
       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) {
                       e.printStackTrace();
                   }
               });
               getStatsThread.start();
               latch.await();
               @Cleanup
               Producer<byte[]> producer = 
pulsarClient.newProducer().topic(topicName).create();
               assertNotNull(producer);
               getStatsThread.join();
           }
       }
   ```
   
   **Expected behavior**
   A topic should get created when topic auto-creation is enabled.


----------------------------------------------------------------
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:
[email protected]


Reply via email to