-
-
Notifications
You must be signed in to change notification settings - Fork 824
Description
Context
In my Android app, I have configured separate Detekt tasks for each variant, including test variants, with the full dependency classpath for each (e.g. detektDebug, detektDebugAndroidTest, etc).
Expected Behavior
I am trying to run multiple at the same time, e.g. ./gradlew detektDebug detektDebugAndroidTest, which Gradle (correctly) infers can happen concurrently.
Observed Behavior
Running multiple Detekt tasks concurrently leads to a deadlock in certain situations. The problem appears to be with ClassLoaderCache: FileCollection.files resolves the included files, but also (unexpectedly to me) blocks until the dependencies are satisfied if they haven't been already. By calling files while being synchronized on ClassLoaderCache, other Detekt invocations become blocked waiting on the monitor, which results in the first Detekt never having its dependencies satisfied, leading to a deadlock.
Steps to Reproduce
I don't have a code sample at the moment (but can provide if necessary) since the configuration and setup would be non-trivial to extract, but the gist is:
- Register a
Detekttask with aclasspathcontaining the classpath of the project's main source set / variant - Register a
Detekttask with aclasspathcontaining the classpath the project's test source set / variant (I think this is important, based on the fact that the test Detekt task will depend on the classpath of the main source set / variant) - Invoke Gradle with both tasks as goals (and sufficient cores/workers to run multiple concurrently)
A thread dump for when I have observed this occurring can be found here:
"Execution worker for ':' Thread 3" #266is blocked onFileCollection.files, having lockedClassLoaderCache"Execution worker for ':' Thread 11" #274is blocked, waiting to lockClassLoaderCache
If I were to provide a suggestion, I think that moving the call to FileCollection.files outside of the synchronized block would be the simplest fix.
Your Environment
- Version of detekt used: 1.12.0
- Version of Gradle used (if applicable): 6.5
- Operating System and version: Mac OS 10.15.6