Possible dead loop

We are encountering a possible dead loop in our CI test build on Jenkins, unfortunately it is intermittent and it is really hard to say what causes it.
Environment:

  • Debian 8
  • Oracle JVM 8
  • Gradle 3.5
    Situation looks like this. Build finishes running integration tests and in most cases succeeds, but intermittently hangs in dead loop (last message of successful build matches last message of locked build). I guess there is one of the workers still running, but have no idea what it is doing. Chunk of debug log attached.
    log.zip (1.4 KB)
    It just endlessly waits and prints those messages over and over until Jenkins cancels build (timeout).
    Any ideas how to debug the reason of this?

Thanks in advance.
UPD.

  • I assume main thread waits for workers to finish, while they are locked
  • Console shows all threads IDLE, while build is not finishing
  • Attaching thread dumps of worker threads and main
    threaddumps.zip (7.1 KB)
  • After upgrading to Gradle 4.1 found one suspicious message in log

Could not stop org.gradle.internal.actor.internal.DefaultActorFactory$NonBlockingActor@2d0cce06.
org.gradle.internal.dispatch.DispatchException: Could not dispatch message [MethodInvocation method: stop()].
at org.gradle.internal.dispatch.ExceptionTrackingFailureHandler.dispatchFailed(ExceptionTrackingFailureHandler.java:34)

Caused by: org.gradle.process.internal.ExecException: Process ‘Gradle Test Executor 68’ finished with non-zero exit value 1
at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:380)
at org.gradle.process.internal.worker.DefaultWorkerProcess.waitForStop(DefaultWorkerProcess.java:190)
at org.gradle.process.internal.worker.DefaultWorkerProcessBuilder$MemoryRequestingWorkerProcess.waitForStop(DefaultWorkerProcessBuilder.java:228)