[ 
https://issues.apache.org/jira/browse/CURATOR-640?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17568061#comment-17568061
 ] 

David White commented on CURATOR-640:
-------------------------------------

Although this bug is listed as fixed in 5.3.0 when I attempt to build version 
5.3.0 there is an internal test that is failing that looks related to this 
issue:

```

[ERROR] Errors: 
[ERROR] 
org.apache.curator.framework.recipes.cache.TestTreeCache.testIsolatedThreadGroup
[ERROR]   Run 1: TestTreeCache.testIsolatedThreadGroup:671 » IllegalThreadState 
Has threads
[ERROR]   Run 2: TestTreeCache.testIsolatedThreadGroup:671 » IllegalThreadState 
Has threads
[ERROR]   Run 3: TestTreeCache.testIsolatedThreadGroup:671 » IllegalThreadState 
Has threads
[INFO] 
[INFO] 
[ERROR] Tests run: 125, Failures: 0, Errors: 1, Skipped: 1
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Apache Curator ..................................... SUCCESS [  2.011 s]
[INFO] Curator Testing .................................... SUCCESS [  8.989 s]
[INFO] Curator Client ..................................... SUCCESS [ 31.152 s]
[INFO] Curator Framework .................................. SUCCESS [10:45 min]
[INFO] Curator Recipes .................................... SUCCESS [29:38 min]
[INFO] Curator Service Discovery .......................... SUCCESS [01:01 min]
[INFO] Curator Async ...................................... SUCCESS [03:25 min]
[INFO] Curator Examples ................................... SUCCESS [  9.240 s]
[INFO] Curator Service Discovery Server ................... SUCCESS [ 37.418 s]
[INFO] curator-test-zk35 .................................. FAILURE [10:48 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 57:08 min
[INFO] Finished at: 2022-07-18T11:17:06-04:00
[INFO] Final Memory: 95M/1024M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on 
project curator-test-zk35: There are test failures.

```

> IllegalThreadStateException thrown when access PathChildrenCache in different 
> thread groups
> -------------------------------------------------------------------------------------------
>
>                 Key: CURATOR-640
>                 URL: https://issues.apache.org/jira/browse/CURATOR-640
>             Project: Apache Curator
>          Issue Type: Bug
>          Components: Recipes
>    Affects Versions: 5.2.1
>            Reporter: Xiaogang Shi
>            Assignee: Zili Chen
>            Priority: Minor
>             Fix For: 5.3.0
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> When we create PathChildrenCache instances without specifying thead factory, 
> the {{defaultThreadFactory}} will be used to create threads. The 
> {{defaultThreadFactory}} is typically backed by 
> {{java.util.concurrent.DefaultThreadFactory}} which will add newly created 
> threads into the thread group where it is instantiated. That is, the 
> {{defaultThreadFactory}} will always add newly created threads into the first 
> thread group that loads the {{PathChildrenCache}} class.
> In cases where {{PathChildrenCache}} is accessed in different thread groups, 
> if the first thread group that load the {{PathChildrenCache}} is destroy, 
> then all attempts to start the {{PathChildrenCache}} will fail.
> The problem can be reproduced using the following code: 
> {code:java}
> ThreadGroup threadGroup1 = new ThreadGroup("testGroup1");
> Thread thread1 = new Thread(threadGroup1, () -> {
>         PathChildrenCache cache1 =
>                 new PathChildrenCache(client, "/test1", true);
>         try {
>             cache1.start();
>             Thread.sleep(1000);
>         } catch (Throwable t) {
>             t.printStackTrace();
>         } finally {
>             try {
>                 cache1.close();
>             } catch (IOException e) {
>                 e.printStackTrace();
>             }
>         }
> });
> thread1.start();
> thread1.join();
> // After the thread group is destroyed, all PathChildrenCache instances 
> // will fail to start due to inability to add new threads into the first 
> thread group
> threadGroup1.destroy();
> ThreadGroup threadGroup2 = new ThreadGroup("testGroup2");
> Thread thread2 = new Thread(threadGroup2, () -> {
>         PathChildrenCache cache2 =
>             new PathChildrenCache(client, "/test1", true);
>         try {
>             cache2.start();
>             Thread.sleep(1000);
>         } catch (Throwable t) {
>             t.printStackTrace();
>         } finally {
>             try {
>                 cache2.close();
>             } catch (IOException e) {
>                 e.printStackTrace();
>             }
>         }
> });
> thread2.start();
> thread2.join();
> {code}
> When starting {{cache2}}, the following exception is thrown:
> {code}
> java.lang.IllegalThreadStateException
>       at java.base/java.lang.ThreadGroup.addUnstarted(ThreadGroup.java:892)
>       at java.base/java.lang.Thread.<init>(Thread.java:434)
>       at java.base/java.lang.Thread.<init>(Thread.java:708)
>       at 
> java.base/java.util.concurrent.Executors$DefaultThreadFactory.newThread(Executors.java:660)
>       at 
> org.apache.curator.shaded.com.google.common.util.concurrent.ThreadFactoryBuilder$1.newThread(ThreadFactoryBuilder.java:163)
>       at 
> java.base/java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:630)
>       at 
> java.base/java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
>       at 
> java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1353)
>       at 
> java.base/java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:721)
>       at 
> org.apache.curator.utils.CloseableExecutorService.submit(CloseableExecutorService.java:191)
>       at 
> org.apache.curator.framework.recipes.cache.PathChildrenCache.submitToExecutor(PathChildrenCache.java:841)
>       at 
> org.apache.curator.framework.recipes.cache.PathChildrenCache.offerOperation(PathChildrenCache.java:792)
>       at 
> org.apache.curator.framework.recipes.cache.PathChildrenCache.start(PathChildrenCache.java:300)
>       at 
> org.apache.curator.framework.recipes.cache.PathChildrenCache.start(PathChildrenCache.java:239)
> {code}



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

Reply via email to