mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(docker): start the Windows binary with or without Docker running (#7166)
* fix(docker): start the Windows binary with or without Docker running The 2.4.0 Windows standalone binary exited at startup with an UnsatisfiedLinkError for Java_com_sun_jna_Native_open. docker-java's named-pipe socket calls JNA when the pipe does not open at once, and JNA was initialized at image build time, so its native dispatch library was loaded into the builder and never into the binary. JNA is now initialized at run time, its JNI metadata (from oracle/graalvm-reachability-metadata, CC0) and a proxy registration for NamedPipeSocket$Kernel32 are bundled, and FlociDockerHttpClient turns a LinkageError from the transport into an exception, so a JNA that still cannot load fails that one Docker call instead of the whole emulator. With JNA working, a Windows host without Docker never answered its health check: docker-java retries a missing pipe for the whole 30 s connect timeout, and DockerRetry retried the NoSuchFileException six times. The pipe is now opened once first and a missing or denied pipe fails at once, keeping docker-java's wait loop for a busy pipe, and DockerRetry no longer retries either error. The release smoke script prints both ends of a long log on failure. Signed-off-by: Hector Ventura <hectorvent@gmail.com> * test(docker): skip the named-pipe client tests on Windows and name the tolerated exception Both tests stand a temporary directory in for a pipe, which only behaves that way off Windows: there a directory opens as access-denied and Kernel32 loads. The busy-pipe catch now names its exception expected, as AGENTS.md asks for a tolerated one. Signed-off-by: Hector Ventura <hectorvent@gmail.com> --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
60500fd28d
commit
2b1d91b7ca
9 files changed
+1428
-4
No files matched your search
@@ -8,6 +8,8 @@ import java.io.InterruptedIOException;
|
||||
import java.net.BindException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.file.AccessDeniedException;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -196,4 +198,14 @@ class DockerRetryTest {
|
||||
assertFalse(DockerRetry.isTransientIo(
|
||||
new IOException("Broken pipe", new SocketException("PERMISSION DENIED"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isTransientIo_missingOrDeniedNamedPipe_isNotTransient() {
|
||||
// Windows without Docker running: the pipe is absent and its exception message is only the
|
||||
// pipe's name, so the message match above cannot see it. Each retry cost a 30 s connect.
|
||||
assertFalse(DockerRetry.isTransientIo(new NoSuchFileException("\\\\.\\pipe\\docker_engine")));
|
||||
assertFalse(DockerRetry.isTransientIo(
|
||||
new RuntimeException(new NoSuchFileException("\\\\.\\pipe\\docker_engine"))));
|
||||
assertFalse(DockerRetry.isTransientIo(new AccessDeniedException("\\\\.\\pipe\\docker_engine")));
|
||||
}
|
||||
}
|
||||
+55
@@ -5,6 +5,8 @@ import org.apache.hc.core5.http.ConnectionRequestTimeoutException;
|
||||
import org.apache.hc.core5.util.TimeValue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.api.condition.DisabledOnOs;
|
||||
import org.junit.jupiter.api.condition.OS;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -18,6 +20,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
@@ -96,6 +99,58 @@ class FlociDockerHttpClientTest {
|
||||
}
|
||||
}
|
||||
|
||||
// Catches: a named-pipe host whose JNA cannot load throwing an Error out of execute(), past
|
||||
// every caller's catch (Exception); at startup that took down the Windows binary. A directory
|
||||
// stands in for a busy pipe: it exists but cannot be opened for writing, so the open fails with
|
||||
// a plain FileSystemException and docker-java's wait loop reaches for Kernel32, which cannot
|
||||
// load off Windows. Not on Windows, where Kernel32 loads and a directory is access-denied.
|
||||
@Test
|
||||
@DisabledOnOs(OS.WINDOWS)
|
||||
@Timeout(30)
|
||||
void aNamedPipeTransportThatCannotLoadItsNativeLibraryFailsTheCallWithAnException(@TempDir Path dir)
|
||||
throws Exception {
|
||||
try (FlociDockerHttpClient client = new FlociDockerHttpClient.Builder()
|
||||
.dockerHost(URI.create("npipe://" + dir.toUri().getPath()))
|
||||
.build()) {
|
||||
for (int attempt = 1; attempt <= 2; attempt++) {
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> client.execute(get("/_ping")));
|
||||
assertTrue(failure.getCause() instanceof LinkageError,
|
||||
"attempt " + attempt + " should wrap the LinkageError, got " + failure.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Catches: a named pipe that does not exist (Windows without Docker running) spending the whole
|
||||
// connect timeout in docker-java's wait loop, and DockerRetry retrying it, so every Docker call
|
||||
// took 30 s per attempt and the binary never answered its health check. Not on Windows, where
|
||||
// a temp-directory path is not a pipe name.
|
||||
@Test
|
||||
@DisabledOnOs(OS.WINDOWS)
|
||||
@Timeout(10)
|
||||
void aNamedPipeThatDoesNotExistFailsAtOnceAndIsNotRetried(@TempDir Path dir) throws Exception {
|
||||
try (FlociDockerHttpClient client = new FlociDockerHttpClient.Builder()
|
||||
.dockerHost(URI.create("npipe://" + dir.resolve("no_such_pipe").toUri().getPath()))
|
||||
.connectionTimeout(Duration.ofSeconds(30))
|
||||
.build()) {
|
||||
long start = System.nanoTime();
|
||||
RuntimeException failure = assertThrows(RuntimeException.class, () -> client.execute(get("/_ping")));
|
||||
long elapsedMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
|
||||
assertTrue(elapsedMs < 5_000, "a missing pipe should fail at once, took " + elapsedMs + " ms");
|
||||
assertTrue(hasCause(failure, NoSuchFileException.class), "expected a NoSuchFileException, got " + failure);
|
||||
assertFalse(DockerRetry.isTransientIo(failure), "a missing pipe must not be retried");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasCause(Throwable t, Class<? extends Throwable> type) {
|
||||
for (Throwable c = t; c != null; c = c.getCause()) {
|
||||
if (type.isInstance(c)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static DockerHttpClient.Request get(String path) {
|
||||
return DockerHttpClient.Request.builder().method(DockerHttpClient.Request.Method.GET).path(path).build();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user