Bug 564202 - java.util.concurrent.RejectedExecutionException when using JGit concurrently in the same application
Summary: java.util.concurrent.RejectedExecutionException when using JGit concurrently ...
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 5.9   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 566938 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-06-11 06:43 EDT by Alexander Schubert CLA
Modified: 2020-09-14 11:04 EDT (History)
2 users (show)

See Also:


Attachments
Java snippet to reproduce problem (1.33 KB, application/octet-stream)
2020-06-11 06:43 EDT, Alexander Schubert CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Schubert CLA 2020-06-11 06:43:51 EDT
Created attachment 283228 [details]
Java snippet to reproduce problem

When using JGit concurrently in the same application, JGit often fails with the following error:

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.CompletableFuture$AsyncSupply@41727a4c rejected from java.util.concurrent.ThreadPoolExecutor@1f27645f[Running, pool size = 5, active threads = 5, queued tasks = 0, completed tasks = 0]
	at java.util.concurrent.CompletableFuture.asyncSupplyStage(CompletableFuture.java:1604)
	at java.util.concurrent.CompletableFuture.supplyAsync(CompletableFuture.java:1830)
	at org.eclipse.jgit.util.FS$FileStoreAttributes.getFileStoreAttributes(FS.java:329)
	at org.eclipse.jgit.util.FS$FileStoreAttributes.get(FS.java:296)
	at org.eclipse.jgit.util.FS.getFileStoreAttributes(FS.java:767)
	at org.eclipse.jgit.internal.storage.file.FileSnapshot.<init>(FileSnapshot.java:224)
	at org.eclipse.jgit.internal.storage.file.FileSnapshot.<init>(FileSnapshot.java:205)
	at org.eclipse.jgit.internal.storage.file.FileSnapshot.save(FileSnapshot.java:102)
	at org.eclipse.jgit.internal.storage.file.FileRepository.<init>(FileRepository.java:209)
	at org.eclipse.jgit.storage.file.FileRepositoryBuilder.build(FileRepositoryBuilder.java:55)
	at Reproducer.lambda$null$0(Reproducer.java:21)

This worked fine until 5.6.1.202002131546-r and started failing on later versions, so I believe this is a regression.

I've attached a small Java snippet to reproduce the problem. Note that it requires an existing working directory of a Git repository to be passed as an argument. Also, it's not completely reliable in reproducing the problem. Disabling JIT compilation in the JVM ('-Xint' for OpenJDK) to change the performance characteristics increased the chances of hitting the problem for me.
Comment 1 Alexander Schubert CLA 2020-06-11 06:57:08 EDT
I believe that this is possibly a regression that was introduced by the following change.
Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=551690
Gerrit: https://git.eclipse.org/r/153691
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=64715a189fe19e8a25bb8757591e3ef60f3f9aa8

It introduced a new ThreadPoolExecutor FUTURE_RUNNER in org.eclipse.jgit.util.FS$FileStoreAttributes (instead of using the common ForkJoinPool). FUTURE_RUNNER uses SynchronousQueue, that doesn't queue requests, with a maximum pool size of 5. This limits the number of concurrent usages of JGit in the same JVM process to the magic number of 5.
Comment 2 Eclipse Genie CLA 2020-06-15 06:38:45 EDT
New Gerrit change created: https://git.eclipse.org/r/164901
Comment 3 Eclipse Genie CLA 2020-07-23 18:29:09 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/166767
Comment 5 Thomas Wolf CLA 2020-09-14 11:04:44 EDT
*** Bug 566938 has been marked as a duplicate of this bug. ***