[ 
https://issues.apache.org/jira/browse/CURATOR-654?focusedWorklogId=818441&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-818441
 ]

ASF GitHub Bot logged work on CURATOR-654:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 19/Oct/22 11:58
            Start Date: 19/Oct/22 11:58
    Worklog Time Spent: 10m 
      Work Description: tisonkun commented on code in PR #435:
URL: https://github.com/apache/curator/pull/435#discussion_r999343775


##########
curator-recipes/src/test/java/org/apache/curator/framework/recipes/barriers/TestDistributedBarrier.java:
##########
@@ -218,4 +230,48 @@ public Object call() throws Exception
             client.close();
         }
     }
+
+    @Test
+    public void     testIsSet() throws Exception
+    {
+        try (CuratorFramework client = 
CuratorFrameworkFactory.newClient(server.getConnectString(), new 
RetryOneTime(1))) {
+            client.start();
+
+            final DistributedBarrier barrier = new DistributedBarrier(client, 
"/barrier");
+            barrier.setBarrier();
+
+            assertTrue(barrier.isSet());
+        }
+    }
+
+    @Test
+    public void     testIsNotSet() throws Exception
+    {
+        try (CuratorFramework client = 
CuratorFrameworkFactory.newClient(server.getConnectString(), new 
RetryOneTime(1))) {
+            client.start();
+
+            final DistributedBarrier barrier = new DistributedBarrier(client, 
"/barrier");
+            barrier.setBarrier();
+            barrier.removeBarrier();
+
+            assertFalse(barrier.isSet());
+        }
+    }
+
+    @Test
+    public void     testWatchersRemoved() throws Exception
+    {
+        CuratorFramework              client = mock(CuratorFramework.class);
+        WatcherRemoveCuratorFramework watcherRemoveClient = 
mock(WatcherRemoveCuratorFramework.class);
+        ExistsBuilder                 existsBuilder = 
mock(ExistsBuilder.class);
+
+        
when(client.newWatcherRemoveCuratorFramework()).thenReturn(watcherRemoveClient);
+        when(watcherRemoveClient.checkExists()).thenReturn(existsBuilder);
+        
when(existsBuilder.usingWatcher(any(Watcher.class))).thenReturn(existsBuilder);
+
+        final DistributedBarrier      barrier = new DistributedBarrier(client, 
"/barrier");
+        barrier.waitOnBarrier(1, TimeUnit.SECONDS);
+        verify(watcherRemoveClient, atLeastOnce()).removeWatchers();
+    }

Review Comment:
   @kezhuw I agree that it can be a bug as I mentioned in 
https://lists.apache.org/thread/0kcnklcxs0s5656c1sbh3crgdodbb0qg. You can reply 
on the mailing list and file an issue.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 818441)
    Time Spent: 40m  (was: 0.5h)

> DistributedBarrier watcher leak
> -------------------------------
>
>                 Key: CURATOR-654
>                 URL: https://issues.apache.org/jira/browse/CURATOR-654
>             Project: Apache Curator
>          Issue Type: Bug
>          Components: Recipes
>    Affects Versions: 5.3.0
>            Reporter: Stuart Scott
>            Priority: Major
>         Attachments: 
> CURATOR-654__Remove_watchers_after_waiting_for_barrier_.patch
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> The DistributedBarrier adds a zookeeper exists watcher in the waitOnBarrier() 
> method. It appears as though the watcher is never removed. In a system where 
> DistributedBarriers are used heavily this eventually results in the system 
> running out of memory.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to