Gradle 7.0.2 no longer working on Ubuntu 20.04

I don’t know what triggered this problem but now none of my projects can build. Also gradle init isn’t working:

gradle-7.0.2/bin/gradle init -S
Starting a Gradle Daemon, 7 busy and 10 stopped Daemons could not be reused, use --status for details
Starting a Gradle Daemon, 8 busy and 10 stopped Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

* What went wrong:
Could not receive a message from the daemon.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.launcher.daemon.client.DaemonConnectionException: Could not receive a message from the daemon.
        at org.gradle.launcher.daemon.client.DaemonClientConnection.receive(DaemonClientConnection.java:83)
        at org.gradle.launcher.daemon.client.DaemonClient.executeBuild(DaemonClient.java:167)
        at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:147)
        at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:98)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:57)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:212)
        at org.gradle.launcher.cli.DefaultCommandLineActionFactory$ParseAndBuildAction.execute(DefaultCommandLineActionFactory.java:275)
        at org.gradle.launcher.cli.DefaultCommandLineActionFactory$ParseAndBuildAction.execute(DefaultCommandLineActionFactory.java:247)
        at org.gradle.launcher.cli.DebugLoggerWarningAction.execute(DebugLoggerWarningAction.java:82)
        at org.gradle.launcher.cli.DebugLoggerWarningAction.execute(DebugLoggerWarningAction.java:30)
        at org.gradle.launcher.cli.WelcomeMessageAction.execute(WelcomeMessageAction.java:92)
        at org.gradle.launcher.cli.WelcomeMessageAction.execute(WelcomeMessageAction.java:38)
        at org.gradle.launcher.cli.NativeServicesInitializingAction.execute(NativeServicesInitializingAction.java:44)
        at org.gradle.launcher.cli.NativeServicesInitializingAction.execute(NativeServicesInitializingAction.java:26)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:41)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:26)
        at org.gradle.launcher.cli.DefaultCommandLineActionFactory$WithLogging.execute(DefaultCommandLineActionFactory.java:240)
        at org.gradle.launcher.Main.doAction(Main.java:35)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:50)
        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:60)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:31)
Caused by: org.gradle.internal.remote.internal.MessageIOException: Could not read message from '/127.0.0.1:43511'.
        at org.gradle.internal.remote.internal.inet.SocketConnection.receive(SocketConnection.java:94)
        at org.gradle.launcher.daemon.client.DaemonClientConnection.receive(DaemonClientConnection.java:77)
        ... 25 more
Caused by: com.esotericsoftware.kryo.KryoException: java.io.IOException: Connessione interrotta dal corrispondente
        at com.esotericsoftware.kryo.io.Input.fill(Input.java:148)
        at com.esotericsoftware.kryo.io.Input.require(Input.java:178)
        at com.esotericsoftware.kryo.io.Input.readVarInt(Input.java:355)
        at com.esotericsoftware.kryo.io.Input.readInt(Input.java:350)
        at org.gradle.internal.serialize.kryo.KryoBackedDecoder.readSmallInt(KryoBackedDecoder.java:127)
        at org.gradle.internal.serialize.DefaultSerializerRegistry$TaggedTypeSerializer.read(DefaultSerializerRegistry.java:142)
        at org.gradle.internal.serialize.Serializers$StatefulSerializerAdapter$1.read(Serializers.java:36)
        at org.gradle.internal.remote.internal.inet.SocketConnection.receive(SocketConnection.java:81)
        ... 26 more
Caused by: java.io.IOException: Connessione interrotta dal corrispondente
        at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
        at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
        at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
        at sun.nio.ch.IOUtil.read(IOUtil.java:192)
        at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379)
        at org.gradle.internal.remote.internal.inet.SocketConnection$SocketInputStream.read(SocketConnection.java:196)
        at com.esotericsoftware.kryo.io.Input.fill(Input.java:146)
        ... 33 more


* Get more help at https://help.gradle.org

I’ve a lot of daemons in UNKNOWN status:

gradle-7.0.2/bin/gradle --status
   PID STATUS   INFO
109466 UNKNOWN  UNKNOWN
109595 UNKNOWN  UNKNOWN
109727 UNKNOWN  UNKNOWN
110134 UNKNOWN  UNKNOWN
110258 UNKNOWN  UNKNOWN
110972 UNKNOWN  UNKNOWN
110999 UNKNOWN  UNKNOWN
111100 UNKNOWN  UNKNOWN

With related processes:

user+  109466  0.5  0.6 3417480 148044 ?      Ssl  18:19   0:03 /usr/lib/jvm/java-1.8.0-amazon-corretto/bin/java -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=IT -Duser.language=it -Duser.variant -cp gradle-7.0.2/lib/gradle-launcher-7.0.2.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.0.2
user+  111481  0.0  0.0   9068  2544 pts/1    S+   18:31   0:00 grep --color=auto 109466
user+  109595  0.5  0.6 3417480 148328 ?      Ssl  18:19   0:03 /usr/lib/jvm/java-1.8.0-amazon-corretto/bin/java -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=IT -Duser.language=it -Duser.variant -cp gradle-7.0.2/lib/gradle-launcher-7.0.2.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.0.2
user+  111483  0.0  0.0   9068   736 pts/1    S+   18:31   0:00 grep --color=auto 109595
user+  110972  0.7  0.5 3415432 143968 ?      Ssl  18:25   0:02 /usr/lib/jvm/java-1.8.0-amazon-corretto/bin/java -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=IT -Duser.language=it -Duser.variant -cp gradle-7.0.2/lib/gradle-launcher-7.0.2.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.0.2
user+  111485  0.0  0.0   8936   660 pts/1    S+   18:31   0:00 grep --color=auto 110972
user+  111100  0.8  0.5 3415432 143120 ?      Ssl  18:25   0:02 /usr/lib/jvm/java-1.8.0-amazon-corretto/bin/java -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=IT -Duser.language=it -Duser.variant -cp gradle-7.0.2/lib/gradle-launcher-7.0.2.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.0.2

Any hints?

Gradle requires interprocess communication to send messages between the client and daemon and query the daemon status. It looks like this communication is being blocked, so double check the any network configuration updates or recent system updates that might have causes undesired side effects.

Thanks @jjustinic

From logs I understand that is using TCP localhost connection for IPC. You pointend me in the right direction.

Found that starting my dockerized openconnect VPN is breaking gradle daemon communication.

I need that VPN and gradle builds coexist so I’ll keep on investigating.

I’ve fallen in this scenario: Android Studio: Failed Gradle execution. Cause: Broken Pipe - Stack Overflow

Using tcpdump on lo I’ve found that connections to gradle daemon was originating from my eth0 IP address (192.168.xxx).

It happens because of this iptables rule generated by the VPN:

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   11  1514 MASQUERADE  all  --  *      *       0.0.0.0/0            0.0.0.0/0       

The fix is 1) delete such rule 2) fix the rule to be more precise with ! -o lo