I am using JGit for downloading repositories from gerrit (using cycle). There are more than 2000 repositories to download. A am getting error approximately on 1000 repo.
The is my method to download repo:
override fun downloadProject(moduleName: String): Path {
val tempDirectory = Files.createTempDirectory(moduleName)
val cloneCommand = Git.cloneRepository()
moduleInfoDao.getModuleByName(moduleName).codeRepository?.let {
cloneCommand.setURI(makeSshUri(it))
} ?: throw ModuleWithoutRepositoryException()
cloneCommand.setTransportConfigCallback { transport ->
val sshTransport = transport as SshTransport
sshTransport.sshSessionFactory = sshSessionFactory
}
cloneCommand.setDirectory(tempDirectory.toFile())
cloneCommand.setBare(false)
val cloneResult = cloneCommand.call()
cloneResult.close()
cloneCommand?.repository?.close()
return tempDirectory
}
The is the exception trace:
2022-09-24 19:26:15.941 [ool-request-processor-thread-1] ERROR Creating lock file /var/folders/6_/h619j3tx5fscmn4q2wr0vqth0000gp/T/module-agents-offline15007549319743888409/.git/HEAD.lock failed - <o.e.j.internal.storage.file.LockFile> - org.eclipse.jgit.internal.storage.file.LockFile.lock(LockFile.java:144) java.nio.file.FileSystemException: /var/folders/6_/h619j3tx5fscmn4q2wr0vqth0000gp/T/module-agents-offline15007549319743888409/.git/HEAD.lock: Too many open files at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:100) at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106) at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218) at java.base/java.nio.file.Files.newByteChannel(Files.java:375) at java.base/java.nio.file.Files.createFile(Files.java:652) at org.eclipse.jgit.util.FS_POSIX.createNewFileAtomic(FS_POSIX.java:428) at org.eclipse.jgit.internal.storage.file.LockFile.lock(LockFile.java:142) at org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate.tryLock(RefDirectoryUpdate.java:56) at org.eclipse.jgit.lib.RefUpdate.link(RefUpdate.java:678) at org.eclipse.jgit.internal.storage.file.FileRepository.create(FileRepository.java:246) at org.eclipse.jgit.api.InitCommand.call(InitCommand.java:103) at org.eclipse.jgit.api.CloneCommand.init(CloneCommand.java:275) at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:173) at ru.myorganization.payin.modules.quality.service.GitDownloaderService.downloadProject(GitDownloaderService.kt:48) at ru.myorganization.payin.modules.quality.service.ProjectDownloadingAbstractnessService.getAbstractnessFactor(ProjectDownloadingAbstractnessService.kt:15) at ru.myorganization.payin.modules.quality.service.StableAbstractionsPrincipleService.getWarnings(StableAbstractionsPrincipleService.kt:25) at ru.myorganization.payin.modules.quality.service.StableAbstractionsPrincipleService$$FastClassBySpringCGLIB$$787d1f0a.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:783) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753) at org.springframework.cache.interceptor.CacheInterceptor.lambda$invoke$0(CacheInterceptor.java:54) at org.springframework.cache.interceptor.CacheAspectSupport.invokeOperation(CacheAspectSupport.java:366) at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:421) at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:345) at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:64) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:698) at ru.myorganization.payin.modules.quality.service.StableAbstractionsPrincipleService$$EnhancerBySpringCGLIB$$42c48c58.getWarnings() at ru.myorganization.payin.modules.quality.service.WarningsCompositeService.getWarnings(WarningsCompositeService.kt:19) at ru.myorganization.payin.modules.quality.controllers.scheduler.FindModuleWarningsScheduler.setWarnings(FindModuleWarningsScheduler.kt:43) at ru.myorganization.payin.modules.quality.controllers.scheduler.FindModuleWarningsScheduler.analyzeAllModules(FindModuleWarningsScheduler.kt:25) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:305) at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) at java.base/java.lang.Thread.run(Thread.java:832)