gradle / gradle

Adaptable, fast automation for all
https://gradle.org
Apache License 2.0
17k stars 4.78k forks source link

It is currently in use by another Gradle instance. #30135

Open ritesh-singh opened 3 months ago

ritesh-singh commented 3 months ago

Current Behavior

Running multiple daemons for the same build, leads to below error

Caused by: java.lang.RuntimeException: Failed to load cache entry 6a01857fda538e97a49cf02cfg40058b for Kotlin DSL version catalog plugin accessors for classpath '22113a1c8cdbe86a08b1b01087432360': Could not load from local cache: Timeout waiting to lock Build cache (/Users/.gradle/caches/build-cache-1). It is currently in use by another Gradle instance.
Owner PID: 89317
Our PID: 99001
Owner Operation: 
Our operation: 
Lock file: /Users/.gradle/caches/build-cache-1/build-cache-1.lock

Expected Behavior

Should not lead to build failure, when multiple daemons are trying to access or modify the cache simultaneously from same location, there needs to be a way to handle concurrent access in a safe way without causing data corruption or any kind of inconsistency.

Context (optional)

No response

Steps to Reproduce

Enable local cache org.gradle.caching=true

Reproducing step

Gradle version

8.6

Build scan URL (optional)

No response

Your Environment (optional)

No response

cookieMr commented 3 months ago

I have similar issue (probably the same). And the issue is not related to version that runs (we use a wide variety of versionst, starting from 8.5, up to latest 8.9).

stacktrace.log

./gradlew clean build test check --rerun --no-build-cache
Starting a Gradle Daemon, 8 stopped Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

* What went wrong:
Gradle could not start your build.
> Cannot create service of type BuildSessionActionExecutor using method LauncherServices$ToolingBuildSessionScopeServices.createActionExecutor() as there is a problem with parameter #21 of type BuildLifecycleAwareVirtualFileSystem.
   > Cannot create service of type BuildLifecycleAwareVirtualFileSystem using method VirtualFileSystemServices$GradleUserHomeServices.createVirtualFileSystem() as there is a problem with parameter #1 of type FileWatchingFilter.
      > Cannot create service of type FileWatchingFilter using method VirtualFileSystemServices$GradleUserHomeServices.createFileWatchingFilter() as there is a problem with parameter #1 of type GlobalCacheLocations.
         > Cannot create service of type GlobalCacheLocations using method GradleUserHomeScopeServices.createGlobalCacheLocations() as there is a problem with parameter #1 of type List<GlobalCache>.
            > Could not create service of type FileAccessTimeJournal using GradleUserHomeScopeServices.createFileAccessTimeJournal().
               > Failed to ping owner of lock for journal cache (/Users/cookie/.gradle/caches/journal-1) (lock id: 5868202984269084883, port: 64760)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 2s

The mentioned --status gives:

./gradlew --status
   PID STATUS   INFO
 58392 IDLE     8.9
 40629 STOPPED  (stop command received)

The --stop helps for the next run.

But the issue (for me) is that when i need to run 2 services on my machine, i can run 1st (after clearing daemons with --stop) but the 2nd service has bad luck and yields an issue with a lock file.


Running 2 services:

./gradlew runFunction
Starting a Gradle Daemon, 1 busy and 1 stopped Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

* What went wrong:
Gradle could not start your build.
> Cannot create service of type BuildSessionActionExecutor using method LauncherServices$ToolingBuildSessionScopeServices.createActionExecutor() as there is a problem with parameter #22 of type ValueSnapshotter.
   > Cannot create service of type ValueSnapshotter using method WorkerSharedBuildSessionScopeServices.createValueSnapshotter() as there is a problem with parameter #1 of type List<ValueSnapshotterSerializerRegistry>.
      > Could not create service of type ResourceSnapshotterCacheService using GradleUserHomeServices.createResourceSnapshotterCacheService().
         > Failed to ping owner of lock for file hash cache (/Users/cookie/.gradle/caches/8.9/fileHashes) (lock id: 7723928161097260250, port: 56168)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1s
 ✘ cookie@cookieMr  ~/Documents/repos/cloud-function-secret   feature-2411  ./gradlew --status
   PID STATUS   INFO
 58392 BUSY     8.9
 12550 IDLE     8.9
 40629 STOPPED  (stop command received)

Only Daemons for the current Gradle version are displayed. For more on this, please refer to https://docs.gradle.org/8.9/userguide/gradle_daemon.html#sec:status in the Gradle documentation.
ov7a commented 3 months ago

This issue needs a decision from the team responsible for that area. They have been informed. Response time may vary.


There are still some parts of Gradle that require exclusive access. The use case about running two builds in parallel (IDE and console) is valid and ideally, Gradle should not fail. Even if it fails, the error should be more descriptive.

cookieMr commented 3 months ago

This issue needs a decision from the team responsible for that area. They have been informed. Response time may vary.

There are still some parts of Gradle that require exclusive access. The use case about running two builds in parallel (IDE and console) is valid and ideally, Gradle should not fail. Even if it fails, the error should be more descriptive.

Hi, thank you for your reply. I truly appreciate that this issue is not slowly sinking in the backlog/issue tracker.

As for the parallelism... yes, this is the ideal case. However, the issue (for me) is also, that when i run just 1 gradle daemon, it blocks 2nd run, even the same cmd in the same terminal window, even when the 1st daemon finished work. The 2nd daemon is complaining about not being able to ping owner of lock for file.

Random question: maybe hash cache is corrupted?

tomekrojek commented 2 months ago

Got similar error when running multiple gradle builds in parallel in a project that has convention plugins kept as composite build. I have daemon disabled but there are multiple gradle executions in parallel at the same time.

ov7a commented 2 months ago

FTR, If anyone can consistently reproduce the issue and can provide a self-contained reproducer project, it would help to investigate this.

ritesh-singh commented 2 months ago

I believe a simple reproducer would be, take any open-source project with gradle local cache enabled - like now-in-android. Run, the build from IDE and CLI at the same time, that should reproduce the issue.

cookieMr commented 1 month ago

It seems the issue is not within this repo.

I am unable to reproduce this issue on my Ubuntu laptop. But i was able to reproduce this on MacOS (13.6.9) before the update. Now on updated MacOS (14.7) the issue is gone. I am running (like a crazy monster about cookies) different gradle tasks/projects/jdk versions/gradle versions and i am not able to reproduce this issue after the update.

@ritesh-singh @tomekrojek can you confirm this observation of mine?

ritesh-singh commented 1 month ago

Unless, this error is fixed in further versions - i don't expect it to be resolved. It should not be dependent on OS IMO.

castelblanque-broadcom commented 1 week ago

I am consistently suffering this issue in my Intel Mac. Latest version of IntelliJ, stopping all daemons always.

Is there any update on this?

phillipgziprecruiter commented 5 days ago

I'm also affected by this consistently:

Gradle 8.8

Build time: 2024-05-31 21:46:56 UTC Revision: 4bd1b3d3fc3f31db5a26eecb416a165b8cc36082

Kotlin: 1.9.22 Groovy: 3.0.21 Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023 JVM: 17.0.8 (Amazon.com Inc. 17.0.8+7-LTS) OS: Mac OS X 15.1 aarch64