Gradle Daemon Not Created

Hello,

I am using Gradle 6.9.1 in my Jenkins environment but I’m having an issue while executing at the same time some executions of the following command “gradle --no-daemon {task}” of the same project.

The issue is that some of the executions can’t create a daemon, so they fail and are not able to continue with the CI/CD proccess.

This is the printed exception:

Successfully started process 'Gradle build daemon'
[2023-04-25T08:45:38.045Z] An attempt to start the daemon took 7.367 secs.
[2023-04-25T08:46:11.821Z] 
[2023-04-25T08:46:11.821Z] FAILURE: Build failed with an exception.
[2023-04-25T08:46:11.821Z] 
[2023-04-25T08:46:11.821Z] * What went wrong:
[2023-04-25T08:46:11.821Z] Timeout waiting to connect to the Gradle daemon.
[2023-04-25T08:46:11.821Z] Daemon uid: 44b1a2c5-ca2e-439b-99a1-65808570e2ac with diagnostics:
[2023-04-25T08:46:11.821Z] Daemon pid: 9078

Do anyone knows how to solve the issue?
Any help will be appreciated,
Thanks.

Well, hard to guess from here.
Gradle tries to start the daemon and then wants to connect to it, but cannot.
Maybe your build agent killed it, or you use invalid arguments for it or something like that.
Maybe have a look at <GRADLE_USER_HOME>/daemon/<version>/ and check whether you find anything interesting in the daemon logs.
Or try to run with --debug to maybe get more information.

Side note: --no-daemon does not disable the daemon, builds are always run in the daemon. It just disables that the daemon is kept running after the build to process further builds.

Nothing interesting in the daemon log:

2023-04-27T08:19:30.440+0100 [DEBUG] [org.gradle.internal.remote.internal.inet.TcpIncomingConnector] Listening on [1f502a5c-0ce5-4699-8992-94e8b721a3db port:37853, addresses:[localhost/127.0.0.1]].
2023-04-27T08:19:30.478+0100 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] Daemon starting at: Thu Apr 27 08:19:30 BST 2023, with address: [1f502a5c-0ce5-4699-8992-94e8b721a3db port:37853, addresses:[localhost/127.0.0.1]]
2023-04-27T08:19:30.482+0100 [INFO] [org.gradle.launcher.daemon.server.DaemonRegistryUpdater] Advertising the daemon address to the clients: [1f502a5c-0ce5-4699-8992-94e8b721a3db port:37853, addresses:[localhost/127.0.0.1]]
2023-04-27T08:19:30.485+0100 [DEBUG] [org.gradle.launcher.daemon.server.DaemonRegistryUpdater] Advertised daemon context: DefaultDaemonContext[uid=857667ad-2f6d-4a75-9068-480cdef6eb0f,javaHome=/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64,daemonRegistryDir=/home/ec2-user/.gradle/daemon,pid=9261,idleTimeout=120000,priority=NORMAL,daemonOpts=--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.base/java.lang=ALL-UNNAMED,--add-opens,java.base/java.lang.invoke=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,-Xms512m,-Xmx4g,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
2023-04-27T08:19:30.496+0100 [DEBUG] [org.gradle.launcher.daemon.registry.PersistentDaemonRegistry] Storing daemon address: [1f502a5c-0ce5-4699-8992-94e8b721a3db port:37853, addresses:[localhost/127.0.0.1]], context: DefaultDaemonContext[uid=857667ad-2f6d-4a75-9068-480cdef6eb0f,javaHome=/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64,daemonRegistryDir=/home/ec2-user/.gradle/daemon,pid=9261,idleTimeout=120000,priority=NORMAL,daemonOpts=--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.base/java.lang=ALL-UNNAMED,--add-opens,java.base/java.lang.invoke=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,-Xms512m,-Xmx4g,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
2023-04-27T08:19:30.525+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire exclusive lock on daemon addresses registry.
2023-04-27T08:19:30.538+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] The file lock is held by a different Gradle process (pid: 9310, lockId: 5529841589515881000). Pinged owner at port 41206
2023-04-27T08:19:30.567+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-04-27T08:19:30.576+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2023-04-27T08:19:30.584+0100 [LIFECYCLE] [org.gradle.launcher.daemon.server.Daemon] Daemon server started.
2023-04-27T08:19:30.585+0100 [DEBUG] [org.gradle.launcher.daemon.bootstrap.DaemonStartupCommunication] Completed writing the daemon greeting. Closing streams...
2023-04-27T08:19:30.593+0100 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] stopOnExpiration() called on daemon
2023-04-27T08:19:30.603+0100 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] awaitExpiration() called on daemon
2023-04-27T08:19:30.604+0100 [DEBUG] [org.gradle.launcher.daemon.server.DaemonStateCoordinator] daemon is running. Sleeping until state changes.
2023-04-27T08:19:40.601+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2023-04-27T08:19:40.602+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-04-27T08:19:40.602+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2023-04-27T08:19:40.604+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2023-04-27T08:19:40.605+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-04-27T08:19:40.606+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2023-04-27T08:19:40.607+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2023-04-27T08:19:40.607+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-04-27T08:19:40.607+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2023-04-27T08:19:40.610+0100 [DEBUG] [org.gradle.launcher.daemon.server.DaemonRegistryUpdater] Storing daemon stop event: after the daemon was no longer found in the daemon registry
2023-04-27T08:19:40.620+0100 [DEBUG] [org.gradle.launcher.daemon.registry.PersistentDaemonRegistry] Storing daemon stop event with timestamp 1682579980616
2023-04-27T08:19:40.628+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire exclusive lock on daemon addresses registry.
2023-04-27T08:19:40.632+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-04-27T08:19:40.640+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2023-04-27T08:19:40.642+0100 [LIFECYCLE] [org.gradle.launcher.daemon.server.DaemonStateCoordinator] Daemon will be stopped at the end of the build after the daemon was no longer found in the daemon registry
2023-04-27T08:19:40.642+0100 [DEBUG] [org.gradle.launcher.daemon.server.DaemonStateCoordinator] Marking daemon stopped due to after the daemon was no longer found in the daemon registry. The daemon is running a build: false
2023-04-27T08:19:40.643+0100 [DEBUG] [org.gradle.launcher.daemon.server.DaemonStateCoordinator] daemon has stopped.
2023-04-27T08:19:40.643+0100 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] stop() called on daemon
2023-04-27T08:19:40.643+0100 [INFO] [org.gradle.launcher.daemon.server.Daemon] Stop requested. Daemon is removing its presence from the registry...
2023-04-27T08:19:40.643+0100 [DEBUG] [org.gradle.launcher.daemon.server.DaemonRegistryUpdater] Removing our presence to clients, eg. removing this address from the registry: [1f502a5c-0ce5-4699-8992-94e8b721a3db port:37853, addresses:[localhost/127.0.0.1]]
2023-04-27T08:19:40.644+0100 [DEBUG] [org.gradle.launcher.daemon.registry.PersistentDaemonRegistry] Removing daemon address: [1f502a5c-0ce5-4699-8992-94e8b721a3db port:37853, addresses:[localhost/127.0.0.1]]
2023-04-27T08:19:40.644+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire exclusive lock on daemon addresses registry.
2023-04-27T08:19:40.645+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-04-27T08:19:40.648+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2023-04-27T08:19:40.649+0100 [DEBUG] [org.gradle.launcher.daemon.server.DaemonRegistryUpdater] Address removed from registry.
Daemon vm is shutting down... The daemon has exited normally or was terminated in response to a user interrupt.
2023-04-27T08:19:40.714+0100 [DEBUG] [org.gradle.launcher.daemon.registry.PersistentDaemonRegistry] Removing daemon address: [1f502a5c-0ce5-4699-8992-94e8b721a3db port:37853, addresses:[localhost/127.0.0.1]]
2023-04-27T08:19:40.714+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire exclusive lock on daemon addresses registry.
2023-04-27T08:19:40.717+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-04-27T08:19:40.730+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.

But maybe is failing the process because when the Gradle process starts to search for the created Gradle daemon It is already in process of stopping itself so It will never connect with the proccess.
Maybe a possible solution would be to increase the timeout of the Gradle daemon but I don’t find any property to do that or to avoid specifying the option --no-daemon.

Well, try whether it works without --no-daemon.
Maybe that also fails and is then a sign that something else is havoc.
Maybe you have some firewall / network configuration that prevents the CLI to talk to the daemon or something like that.

I have tried without the --no-daemon option and also with a stress command to put in stress the machine so I can make It more susceptible to fail and It seems that It works for now.

But I don’t like this option because a possible share of resource between builds in the CI environment, so I have updated the Gradle version to 7.3.1 and to Java 17, also I have changed to start using the Gradlew provided by every project and as I can see is working too.

I can’t be sure that these solutions will work always because is an error that only happens sometimes while searching for daemon, so I will keep It under investigation.

1 Like