fix(docker): do not retry a call when the Docker socket does not exist (#5424)

* fix(docker): do not retry a call when the Docker socket does not exist

Without a mounted Docker socket, every Docker call failed with
"No such file or directory" and was retried six times, about 15
seconds. The ECS check for leftover containers runs at startup, so
Floci opened port 4566 only after all the retries.

A missing socket file does not come back on a retry, so DockerRetry no
longer treats this error as transient.

Closes #5342

* fix(docker): do not retry a call when access to the Docker socket is denied

When the Docker socket exists but Floci may not open it, every Docker
call failed with "Permission denied" and was retried six times, about
15 seconds. This also held each Docker call of the shutdown cleanup.

A retry cannot change the permissions of the process, so DockerRetry no
longer treats this error as transient, like a missing socket file.
This commit is contained in:
Aymen JAMAAOUI authored and GitHub committed 2026-10-11 22:16:40 -05:00
1 parent cc129007e4
commit dd6bf4cfcb
3 files changed
+73 -1

No files matched your search

@@ -73,7 +73,8 @@ public final class DockerRetry {
/**
* True when {@code t} (or any cause in its chain) is a transient docker I/O failure worth
* retrying, an {@link IOException} such as {@code Broken pipe} / {@code Connection reset},
* possibly wrapped by docker-java in a {@link RuntimeException}.
* possibly wrapped by docker-java in a {@link RuntimeException}. A docker socket file that is
* missing, or that this process may not open, is never transient.
*/
public static boolean isTransientIo(Throwable t) {
// InterruptedIOException covers both a genuine thread interruption (masking it would
@@ -94,6 +95,9 @@ public final class DockerRetry {
if (c instanceof LocalFailure) {
return false;
}
if (isUnusableSocket(c)) {
return false;
}
if (c.getCause() == c) {
break;
}
@@ -120,6 +124,22 @@ public final class DockerRetry {
return false;
}
/**
* True when {@code t} reports that the docker socket file does not exist ({@code No such
* file or directory}), as when Floci runs without a mounted docker socket, or that this
* process may not open it ({@code Permission denied}). A retry cannot create the file or
* change the process's permissions, so retrying only delays the failure: six attempts held
* Floci's startup, and each docker call of its shutdown, for about 15 seconds.
*/
private static boolean isUnusableSocket(Throwable t) {
String m = t.getMessage();
if (m == null) {
return false;
}
String lower = m.toLowerCase(Locale.ROOT);
return lower.contains("no such file or directory") || lower.contains("permission denied");
}
/**
* Runs {@code call}, retrying up to {@code maxAttempts} times on a transient docker I/O
* error ({@link #isTransientIo}) with a capped exponential backoff between attempts
@@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.BindException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
@@ -174,4 +176,24 @@ class DockerRetryTest {
assertTrue(DockerRetry.isTransientIo(new RuntimeException("BROKEN PIPE")));
assertTrue(DockerRetry.isTransientIo(new RuntimeException("Broken Pipe")));
}
@Test
void isTransientIo_missingDockerSocket_isNotTransient() {
// Floci started without a mounted docker socket: a retry cannot create the file.
assertFalse(DockerRetry.isTransientIo(new SocketException("No such file or directory")));
assertFalse(DockerRetry.isTransientIo(
new RuntimeException(new SocketException("No such file or directory"))));
assertFalse(DockerRetry.isTransientIo(
new IOException("Broken pipe", new SocketException("NO SUCH FILE OR DIRECTORY"))));
}
@Test
void isTransientIo_dockerSocketPermissionDenied_isNotTransient() {
// The socket file exists but this process may not open it: a retry cannot change that.
assertFalse(DockerRetry.isTransientIo(new BindException("Permission denied")));
assertFalse(DockerRetry.isTransientIo(
new RuntimeException(new BindException("Permission denied"))));
assertFalse(DockerRetry.isTransientIo(
new IOException("Broken pipe", new SocketException("PERMISSION DENIED"))));
}
}
@@ -9,6 +9,8 @@ import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.BindException;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
@@ -408,6 +410,34 @@ class RetryingDockerHttpClientTest {
assertEquals(1, rejectedDelegate.calls.get());
}
@Test
void execute_missingDockerSocket_failsWithoutRetry() {
RuntimeException missingSocket = new RuntimeException(new SocketException("No such file or directory"));
FakeTransport delegate = new FakeTransport(attempt -> {
throw missingSocket;
});
RetryingDockerHttpClient client = new RetryingDockerHttpClient(delegate, MAX_ATTEMPTS, 0L);
Request list = Request.builder().method(Request.Method.GET).path("/containers/json").build();
RuntimeException thrown = assertThrows(RuntimeException.class, () -> client.execute(list));
assertSame(missingSocket, thrown);
assertEquals(1, delegate.calls.get(), "a missing docker socket must not be retried");
}
@Test
void execute_dockerSocketPermissionDenied_failsWithoutRetry() {
RuntimeException denied = new RuntimeException(new BindException("Permission denied"));
FakeTransport delegate = new FakeTransport(attempt -> {
throw denied;
});
RetryingDockerHttpClient client = new RetryingDockerHttpClient(delegate, MAX_ATTEMPTS, 0L);
Request inspect = Request.builder().method(Request.Method.GET).path("/volumes/data").build();
RuntimeException thrown = assertThrows(RuntimeException.class, () -> client.execute(inspect));
assertSame(denied, thrown);
assertEquals(1, delegate.calls.get(), "a docker socket this process may not open must not be retried");
}
@Test
void producerWrapsControlPlaneTransportOnly() {
DockerHttpClient raw = new FakeTransport(attempt -> null);