[GRADLE-1991] Can't run two gradle instances at the same time Created: 09/Dec/11  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-milestone-6
Fix Version/s: None

Type: Bug
Reporter: Stanford S. Guillory Assignee: Unassigned
Resolution: Won't Fix Votes: 6


 Description   

I have a service tier in one sub-project that I run using the JavaExec task. I have another project which is a war project and is a client of that service tier. I run it using the jetty plugin. I get the following error when I try to run them at the same time:

Could not open cache directory /home/developer/.gradle/caches/1.0-milestone-6/scripts/build_5rl337remrtkg6ga5c9qg57f4l/ProjectScript/buildscript.
Cause: java.lang.NullPointerException (no error message)



 Comments   
Comment by Adam Murdoch [ 13/Dec/11 ]

Do you have a stacktrace for the failure? You can run gradle with -s to get this.

Comment by Stanford S. Guillory [ 21/Feb/12 ]

Sure. Here you go. Sorry I'm so late for this. Really would like to run both tiers of my app with Gradle, but this behavior is blocking me.

developer@gustloff:~/work/commerce-git/commerce-project/web$ gradle -s tomcatRun
The SourceSet.getClasses() method has been deprecated and will be removed in the next version of Gradle. Please use the getOutput() method instead.

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not open buildscript class cache for build file '/home/developer/work/commerce-git/commerce-project/web/build.gradle' (/home/developer/.gradle/caches/1.0-milestone-8/scripts/build_5rl337remrtkg6ga5c9qg57f4l/ProjectScript/buildscript).
    > Timeout waiting to lock buildscript class cache for build file '/home/developer/work/commerce-git/commerce-project/web/build.gradle' (/home/developer/.gradle/caches/1.0-milestone-8/scripts/build_5rl337remrtkg6ga5c9qg57f4l/ProjectScript/buildscript). It is currently in use by another Gradle instance.
    Owner PID: 27416
    Our PID: 30546
    Owner Operation:
    Our operation:
    Lock file: /home/developer/.gradle/caches/1.0-milestone-8/scripts/build_5rl337remrtkg6ga5c9qg57f4l/ProjectScript/buildscript/cache.properties.lock
  • Try:
    Run with --info or --debug option to get more log output.
  • Exception is:
    org.gradle.cache.CacheOpenException: Could not open buildscript class cache for build file '/home/developer/work/commerce-git/commerce-project/web/build.gradle' (/home/developer/.gradle/caches/1.0-milestone-8/scripts/build_5rl337remrtkg6ga5c9qg57f4l/ProjectScript/buildscript).
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:53)
    at org.gradle.cache.internal.DefaultCacheFactory$CacheFactoryImpl.doOpenDir(DefaultCacheFactory.java:62)
    at org.gradle.cache.internal.DefaultCacheFactory$CacheFactoryImpl.open(DefaultCacheFactory.java:100)
    at org.gradle.cache.internal.DefaultCacheRepository$PersistentCacheBuilder.doOpen(DefaultCacheRepository.java:170)
    at org.gradle.cache.internal.DefaultCacheRepository$PersistentCacheBuilder.doOpen(DefaultCacheRepository.java:126)
    at org.gradle.cache.internal.DefaultCacheRepository$AbstractCacheBuilder.open(DefaultCacheRepository.java:113)
    at org.gradle.groovy.scripts.internal.FileCacheBackedScriptClassCompiler.compile(FileCacheBackedScriptClassCompiler.java:48)
    at org.gradle.groovy.scripts.internal.ShortCircuitEmptyScriptCompiler.compile(ShortCircuitEmptyScriptCompiler.java:35)
    at org.gradle.groovy.scripts.internal.CachingScriptClassCompiler.compile(CachingScriptClassCompiler.java:36)
    at org.gradle.groovy.scripts.DefaultScriptCompilerFactory$ScriptCompilerImpl.compile(DefaultScriptCompilerFactory.java:60)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:114)
    at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)
    at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:478)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:75)
    at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)
    at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)
    at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:38)
    at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:35)
    at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:454)
    at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:449)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:139)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:78)
    at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:42)
    at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:28)
    at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:32)
    at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:21)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:238)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:222)
    at org.gradle.launcher.Main.doAction(Main.java:48)
    at org.gradle.launcher.exec.EntryPoint$1.execute(EntryPoint.java:53)
    at org.gradle.launcher.exec.EntryPoint$1.execute(EntryPoint.java:51)
    at org.gradle.launcher.exec.Execution.execute(Execution.java:28)
    at org.gradle.launcher.exec.EntryPoint.run(EntryPoint.java:39)
    at org.gradle.launcher.Main.main(Main.java:39)
    at org.gradle.launcher.ProcessBootstrap.runNoExit(ProcessBootstrap.java:51)
    at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:33)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:24)
    Caused by: org.gradle.cache.internal.LockTimeoutException: Timeout waiting to lock buildscript class cache for build file '/home/developer/work/commerce-git/commerce-project/web/build.gradle' (/home/developer/.gradle/caches/1.0-milestone-8/scripts/build_5rl337remrtkg6ga5c9qg57f4l/ProjectScript/buildscript). It is currently in use by another Gradle instance.
    Owner PID: 27416
    Our PID: 30546
    Owner Operation:
    Our operation:
    Lock file: /home/developer/.gradle/caches/1.0-milestone-8/scripts/build_5rl337remrtkg6ga5c9qg57f4l/ProjectScript/buildscript/cache.properties.lock
    at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.lock(DefaultFileLockManager.java:232)
    at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.writeToFile(DefaultFileLockManager.java:141)
    at org.gradle.cache.internal.DefaultPersistentDirectoryCache.init(DefaultPersistentDirectoryCache.java:61)
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:47)
    ... 39 more

BUILD FAILED

Total time: 1 mins 3.07 secs

Comment by Stanford S. Guillory [ 21/Feb/12 ]

Actually, this doesn't look like it is related to trying to run two instances of Gradle at the same time (I have upgraded to milestone 8 since the original issue was created). Now it looks like consecutive runs of the tomcat plugin are leaving a lock file behind that is preventing the second run from succeeding.

Comment by Stanford S. Guillory [ 21/Feb/12 ]

Okay, here is the behavior I am seeing. If I run "gradle tomcatRun" (invokes Tomcat plugin) twice in a shell (killing the first instance), the second fails due to the lock file. If I run "gradle runService" in another shell (this invokes java exec) using a different gradle script. I can then go back to the original shell and run the tomcat plugin. Somehow invoking the other gradle script cleans up the lock file issue.

Comment by Adam Murdoch [ 08/May/12 ]

This should be fixed now. Can you try a recent snapshot and let us know how you go: http://gradle.org/nightly?

Comment by Stanford S. Guillory [ 22/Jul/13 ]

Okay, I am seeing this again with 1.6. If I start my service tier with one gradle session then start my web app using the tomcat plugin in another gradle session, I get the following error. If I start the web app first and then the service tier, things start up okay: stan.guillory(gradle_build):~/work/commerce-project/web$ gradle tomcatRun FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring project ':web'. > Could not open buildscript class cache for build file '/home/developer/work/commerce-project/web/build.gradle' (/home/developer/.gradle/caches/1.6/scripts/build_43a7n0vj0jtj9ifdrml9d5li9s/ProjectScript/buildscript). > Timeout waiting to lock buildscript class cache for build file '/home/developer/work/commerce-project/web/build.gradle' (/home/developer/.gradle/caches/1.6/scripts/build_43a7n0vj0jtj9ifdrml9d5li9s/ProjectScript/buildscript). It is currently in use by another Gradle instance. Owner PID: unknown Our PID: 10647 Owner Operation: unknown Our operation: Lock file: /home/developer/.gradle/caches/1.6/scripts/build_43a7n0vj0jtj9ifdrml9d5li9s/ProjectScript/buildscript/cache.properties.lock * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 1 mins 5.268 secs

Comment by Stanford S. Guillory [ 21/Aug/13 ]

I am not seeing this in 1.7.

Comment by Joachim Nilsson [ 06/Sep/13 ]

I am seeing this in 1.7. Well not exactly the same issue, but the same result: cannot run two instances at the same time. The 'other' PID is is not a hanging process, that was my first try to solve it.
Should I create a new issue instead?

The error happens when running Gradle wrapper from Jenkins. The setup is one master job that pulls new code from the Git repo and makes a build. Following that job, there are 15 parallel jobs running integration tests with different setup towards external systems/servers.

  • Exception is:
    org.gradle.cache.CacheOpenException: Could not open task artifact state cache (/scm/hudson/jobs/2216/workspace/repo/.gradle/1.7/taskArtifacts).
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:55)
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:27)
    at org.gradle.cache.internal.DefaultCacheFactory$CacheFactoryImpl.doOpenDir(DefaultCacheFactory.java:72)
    at org.gradle.cache.internal.DefaultCacheFactory$CacheFactoryImpl.open(DefaultCacheFactory.java:111)
    at org.gradle.cache.internal.DefaultCacheRepository$PersistentCacheBuilder.doOpen(DefaultCacheRepository.java:184)
    at org.gradle.cache.internal.DefaultCacheRepository$PersistentCacheBuilder.doOpen(DefaultCacheRepository.java:134)
    at org.gradle.cache.internal.DefaultCacheRepository$AbstractCacheBuilder.open(DefaultCacheRepository.java:121)
    at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.getCache(DefaultTaskArtifactStateCacheAccess.java:44)
    at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
    at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:48)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.Main.main(Main.java:39)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
    Caused by: org.gradle.cache.internal.LockTimeoutException: Timeout waiting to lock task artifact state cache (/scm/hudson/jobs/2216/workspace/repo/.gradle/1.7/taskArtifacts). It is currently in use by another Gradle instance.
    Owner PID: 10367
    Our PID: 24580
    Owner Operation:
    Our operation:
    Lock file: /scm/hudson/jobs/2216/workspace/repo/.gradle/1.7/taskArtifacts/cache.properties.lock
    at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.lock(DefaultFileLockManager.java:303)
    at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.<init>(DefaultFileLockManager.java:143)
    at org.gradle.cache.internal.DefaultFileLockManager.lock(DefaultFileLockManager.java:91)
    at org.gradle.cache.internal.DefaultFileLockManager.lock(DefaultFileLockManager.java:78)
    at org.gradle.cache.internal.DefaultCacheAccess.open(DefaultCacheAccess.java:88)
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:45)
    ... 42 more
Comment by Torsten Krah [ 24/Apr/14 ]

Same here with 1.11. Running parallel Gradle Jobs on Jenkins sometimes fails with this exception about locking the modules-2 cache directory.

* What went wrong:
A problem occurred configuring root project 'index_lucene-dev'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Timeout waiting to lock artifact cache (/home/jenkins/.gradle/caches/modules-2). It is currently in use by another Gradle instance.
     Owner PID: 25575
     Our PID: 24046
     Owner Operation: resolve configuration ':util:compile'
     Our operation: resolve configuration ':classpath'
     Lock file: /home/jenkins/.gradle/caches/modules-2/modules-2.lock
Comment by Richard Doktorics [ 29/Apr/14 ]

Same problem as for Torsten Krah. If we running 2 gradle which are using the same cache then it cause this lock issue.
Temporary solution: We using 2 separated cache.

A problem occurred configuring root project 'poject'.
> Could not resolve all dependencies for configuration ':classpath'.
> Timeout waiting to lock artifact cache (/root/.gradle/caches/modules-2). It is currently in use by another Gradle instance.
Owner PID: 7913
Our PID: 16
Owner Operation: resolve configuration ':my-job:compile'
Our operation: resolve configuration ':classpath'
Lock file: /root/.gradle/caches/modules-2/modules-2.lock

Comment by Torsten Krah [ 29/Apr/14 ]

At the moment we've got about 20+ Gradle projects, about 8 of them can be build in parallel and because there are 8 processors they do sometimes. Its a burden to configure for each parallel builds a separate cache - as projects are growing, this will become unmaintainable, not to speak about cache sizes.

Comment by Richard Doktorics [ 29/Apr/14 ]

True. But currently We didn't have any better idea (If we running 2/or more build then the problem comes immediately so not just sometimes). If you have any better solution then please suggest

Comment by Torsten Krah [ 29/Apr/14 ]

Don't mind - i don't have Richard - its the current workaround. I only want to indicate thats this workaround is no real long term solution (not that the existence of a workaround, does decrease the weight of this task) - that was my intention about my comment, you're absolutely right with that workaround in the short run.

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 12:09:51 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.