Gradle daemon intermittently crashes?

I know we’re using a very old version, and we’re working to upgrade.

In the meantime, how can I debug this issue where the daemon intermittently crash. I’m confused because we don’t use a daemon in our Jenkins build servers, i.e., we have org.gradle.daemon=false in our gradle.properties file? Using the --debug option doesn’t really tell me more?

$ ./gradlew --version

------------------------------------------------------------
Gradle 2.9
------------------------------------------------------------

> Build time:   2015-11-17 07:02:17 UTC
> Build number: none
> Revision:     b463d7980c40d44c4657dc80025275b84a29e31f
> 
> Groovy:       2.4.4
> Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
> JVM:          1.8.0_181 (Oracle Corporation 25.181-b13)
> OS:           Mac OS X 10.14.5 x86_64


FAILURE: Build failed with an exception.

* What went wrong:
Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)

* Try:
Run with --debug option to get more log output.

* Exception is:
org.gradle.launcher.daemon.client.DaemonDisappearedException: Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
	at org.gradle.launcher.daemon.client.DaemonClient.handleDaemonDisappearance(DaemonClient.java:222)
	at org.gradle.launcher.daemon.client.DaemonClient.monitorBuild(DaemonClient.java:198)
	at org.gradle.launcher.daemon.client.DaemonClient.executeBuild(DaemonClient.java:162)
	at org.gradle.launcher.daemon.client.SingleUseDaemonClient.execute(SingleUseDaemonClient.java:55)
	at org.gradle.launcher.daemon.client.SingleUseDaemonClient.execute(SingleUseDaemonClient.java:37)
	at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43)
	at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:170)
	at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
	at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
	at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
	at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
	at org.gradle.launcher.Main.doAction(Main.java:33)
	at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
	at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
	at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
	at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
	at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)

I believe a daemon process is still started even if you specify that you want to disable the daemon. However, it will stop automatically once the build finishes. This is also the default behavior in versions prior to 3.0.

We’ve had a problem with our Jenkins builds with the daemon enabled, that also caused a DaemonDisappearedException. In our case, it was because Jenkins automatically tries to kill any process that is spawned during a build. So if one job starts a daemon, and another job makes use of that same daemon, once the first job finishes, it will kill the daemon and this cases it to disappear from the perspective of the second job. In your case, I guess it could be that Jenkins gets confused as to what short-lived daemon is spawned in one job, and kills all daemon processes even if started from different jobs.

In any case, to get around it, you can try disabling the “process tree killer” in Jenkins. This has the added benefit that you have the option of enabling the daemon to speeds up your builds, though you probably want to upgrade first. To do this, you need to set a property for Jenkins as documented here. We’ve been using the Gradle daemon in our Jenkins builds for a while now, and haven’t seen any problems with it after we disabled the process killer.

Thanks @Bjorn_Vester but this did not help my case, where I experience this issue on pipeline jobs. I set the option to disable ProcessTreeKiller but still see Gradle crashes with the same error.

Well that sucks :frowning:

If you didn’t already, check if there anything of interest in the Daemon log files. (By default, they should be in /.gradle/daemon in the user’s home directory.) Maybe that can give some clues as to why they disappear and if they are in fact short-lived “no daemon” processes.

@Bjorn_Vester thanks again, I’ll look there. However, disabling the ProcessTreeKiller seems to not work for pipeline jobs from the interweb consensus.