How to change the bind ip address of Gradle daemon/process

How to change the listen ip address of gradle daemon or processes. It is always listening and advertising loopback address, which is not reachable from other containers, to the clients. This is causing issue timeouts when processes that are running on separate containers waiting for the file/lock which is held by other process. I want to change the bind address to be private ip address of the container so that processes can ping others for releasing the locks.

Logs:

2024-10-01T05:56:50.763+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] The file lock is held by a different Gradle process (pid: 318, lockId: -7497248990956579849). Pinged owner at port 39775
2024-10-01T05:56:53.025+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] The file lock is held by a different Gradle process (pid: 318, lockId: -7497248990956579849). Pinged owner at port 39775
2024-10-01T05:56:54.585+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] The file lock is held by a different Gradle process (pid: 318, lockId: -7497248990956579849). Pinged owner at port 39775
2024-10-01T05:56:57.354+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] The file lock is held by a different Gradle process (pid: 318, lockId: -7497248990956579849). Pinged owner at port 39775
2024-10-01T05:56:59.076+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] The file lock is held by a different Gradle process (pid: 318, lockId: -7497248990956579849). Pinged owner at port 39775
2024-10-01T05:56:59.564+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2024-10-01T05:56:59.572+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2024-10-01T05:56:59.579+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2024-10-01T05:56:59.590+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2024-10-01T05:56:59.597+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2024-10-01T05:56:59.611+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2024-10-01T05:57:00.276+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] The file lock is held by a different Gradle process (pid: 318, lockId: -7497248990956579849). Pinged owner at port 39775
2024-10-01T05:57:00.297+0000 [DEBUG] [org.gradle.deployment.internal.DefaultDeploymentRegistry] Stopping 0 deployment handles
2024-10-01T05:57:00.297+0000 [DEBUG] [org.gradle.deployment.internal.DefaultDeploymentRegistry] Stopped deployment handles
2024-10-01T05:57:00.347+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
2024-10-01T05:57:00.348+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
2024-10-01T05:57:00.348+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
2024-10-01T05:57:00.349+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
2024-10-01T05:57:00.349+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Gradle could not start your build.
2024-10-01T05:57:00.349+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Could not create service of type ResourceSnapshotterCacheService using GradleUserHomeServices.createResourceSnapshotterCacheService().
2024-10-01T05:57:00.363+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]    > Timeout waiting to lock file hash cache (/home/gradle/.gradle/caches/6.9/fileHashes). It is currently in use by another Gradle instance.
2024-10-01T05:57:00.364+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]      Owner PID: 318
2024-10-01T05:57:00.364+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]      Our PID: 316
2024-10-01T05:57:00.364+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]      Owner Operation: 
2024-10-01T05:57:00.367+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]      Our operation: 
2024-10-01T05:57:00.367+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]      Lock file: /home/gradle/.gradle/caches/6.9/fileHashes/fileHashes.lock

Don’t quote me on that, but I doubt this is possible.
Iirc the code correctly, then it always uses the loopback address unless it cannot find any but remote addresses.
In that case it listens on the remote address or wildcard address, but even then only accepting connections from the remote addresses of the own machine, not from any other addresses.

You probably should not mount the same GRADLE_USER_HOME into multiple containers.
If your main concern is about dependency cache for not redownloading dependencies all the time, you should probably have a look at Understanding dependency resolution and maybe consider a read-only cache that you mount to the containers for example.

From the logs I see that its able to find other private IP (Its reading all network interfaces) and also its added to the context but listening and advertising is happening with only loopback address.

Logs:

2024-10-01T05:55:59.409+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface eth0

2024-10-01T05:55:59.410+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false

2024-10-01T05:55:59.410+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding **remote address /172.17.0.4**

2024-10-01T05:55:59.411+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface lo

2024-10-01T05:55:59.411+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? true

2024-10-01T05:55:59.415+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding loopback address /0:0:0:0:0:0:0:1%lo

2024-10-01T05:55:59.415+0000 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding loopback address /127.0.0.1

2024-10-01T05:55:59.418+0000 [DEBUG]

[org.gradle.internal.remote.internal.inet.TcpIncomingConnector] Listening on [240efb92-74e5-4a1a-a4cc-3a29e1234567 port:43651, **addresses:[localhost/127.0.0.1]].**

2024-10-01T05:55:59.432+0000 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] Daemon starting at: Tue Oct 01 05:55:59 UTC 2024, with address: [240efb92-74e5-4a1a-a4cc-3a29e1234567 port:43651, **addresses:[localhost/127.0.0.1]]**

2024-10-01T05:55:59.433+0000 [INFO] [org.gradle.launcher.daemon.server.DaemonRegistryUpdater] Advertising the daemon address to the clients: [240efb92-74e5-4a1a-a4cc-3a29e1234567 port:43651, **addresses:[localhost/127.0.0.1]]**

2024-10-01T05:55:59.433+0000 [DEBUG] [org.gradle.launcher.daemon.server.DaemonRegistryUpdater] Advertised daemon context: DefaultDaemonContext[uid=b9adc833-c1d2-4230-86d1-d8b0d9b716e6,javaHome=/opt/java/openjdk,daemonRegistryDir=/home/gradle/.gradle/daemon,pid=316,idleTimeout=10800000,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,-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]

2024-10-01T05:55:59.435+0000 [DEBUG] [org.gradle.launcher.daemon.registry.PersistentDaemonRegistry] Storing daemon address: [240efb92-74e5-4a1a-a4cc-3a29e1234567 port:43651, addresses:[localhost/127.0.0.1]], context: DefaultDaemonContext[uid=b9adc833-c1d2-4230-86d1-d8b0d9b716e6,javaHome=/opt/java/openjdk,daemonRegistryDir=/home/gradle/.gradle/daemon,pid=316,idleTimeout=10800000,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,-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]

From the logs I see that its able to find other private IP (Its reading all network interfaces) and also its added to the context but listening and advertising is happening with only loopback address.

That’s exactly matching what I just told you. :wink:

1 Like

Hi @VampireIs is there any alternative to execute two parallel builds as separate processes in different containers while still sharing the same cache (NFS) to reuse dependencies?

I have no idea, but I highly doubt it.
Really sounds like you should use a read-only cache for example.
:man_shrugging: