[GRADLE-2315] FileNotFoundException when trying to get RandomAccessFile handle to artifacts directory lock file due to another process having a lock on the file Created: 18/May/12  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Won't Fix Votes: 1


Exception looks like this:

java.io.FileNotFoundException: C:\Users\krik\.gradle\caches\artifacts-8\artifacts-8.lock (The process cannot access the file because it is being used by another process)

Based on the artifact cache number, we can see that this is an older version. No report on whether the most recent version has the same problem but I suspect it will.

The problem occurs when we create a RandomAccessFile with rw mode for the lock file. The JavaDoc indicates that this can fail if another process holds a lock on the file.

Comment by Gradle Forums [ 18/May/12 ]


Can you please provide the full stacktrace for this error. To do this, you need to run Gradle with the `-s` switch.

Comment by Gradle Forums [ 18/May/12 ]

Caused by: org.gradle.internal.UncheckedException: java.io.FileNotFoundException: C:\Users\lkeyoth\.gradle\caches\artifacts-8\artifacts-8.lock (The process cannot access the file because it is being used by another process)

at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:39)

at org.gradle.cache.internal.DefaultFileLockManager.lock(DefaultFileLockManager.java:71)

at org.gradle.cache.internal.DefaultCacheAccess.getLock(DefaultCacheAccess.java:274)

at org.gradle.cache.internal.DefaultCacheAccess.access$100(DefaultCacheAccess.java:39)

at org.gradle.cache.internal.DefaultCacheAccess$UnitOfWorkFileAccess.writeToFile(DefaultCacheAccess.java:285)

at org.gradle.cache.internal.MultiProcessSafePersistentIndexedCache.getCache(MultiProcessSafePersistentIndexedCache.java:84)

at org.gradle.cache.internal.MultiProcessSafePersistentIndexedCache.get(MultiProcessSafePersistentIndexedCache.java:35)

at org.gradle.api.internal.artifacts.ivyservice.dynamicversions.SingleFileBackedModuleResolutionCache.getCachedModuleResolution(SingleFileBackedModuleResolutionCache.java:66)

at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleVersionRepository.maybeUseCachedDynamicVersion(CachingModuleVersionRepository.java:93)

at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleVersionRepository.findModule(CachingModuleVersionRepository.java:83)

at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleVersionRepository.getDependency(CachingModuleVersionRepository.java:79)

at sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.IvyContextualiser$1.invoke(IvyContextualiser.java:44)

at $Proxy33.getDependency(Unknown Source)

at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain.findLatestModule(UserResolverChain.java:71)

at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain.resolve(UserResolverChain.java:52)

... 99 more

Caused by: java.io.FileNotFoundException: C:\Users\lkeyoth\.gradle\caches\artifacts-8\artifacts-8.lock (The process cannot access the file because it is being used by another process)

at java.io.RandomAccessFile.open(Native Method)

at java.io.RandomAccessFile.(RandomAccessFile.java:216)

at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.(DefaultFileLockManager.java:96)

at org.gradle.cache.internal.DefaultFileLockManager.lock(DefaultFileLockManager.java:68)

... 115 more

Comment by Gradle Forums [ 18/May/12 ]

Is this happening consistently?

How often does it happen?

If its intermittent, is there any triggering factor that you've noticed?

Can you please post your Gradle version and information about your OS version.

Comment by Gradle Forums [ 18/May/12 ]

i saw this happen in multiple machines. very random but is happening at lease once a day. I have to restart my machine as a work around. i got his error again now.

Comment by James Poje [ 29/May/12 ]

I have also seen gradle trip over its lockfile in multiple versions, including 1.0-rc-3 (seemed worst around milestone-5). It occurs only sporadically and seems to be linked to downloading a lot of artifacts, though I cannot reliably reproduce.

Could this note from the user guide be related? "The lock is held whenever the binary meta-data store is being read or written, but is released for slow operations such as downloading remote artifacts."

Comment by James Poje [ 05/Jul/12 ]

Update after moving to gradle-1.0: still seeing this behavior sporadically, even when using --offline. I haven't noticed any apparent trigger.

Comment by Peter Niederwieser [ 05/Jul/12 ]

Which OS?

Comment by James Poje [ 05/Jul/12 ]

This is on windows7 64bit.

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:18:36 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.