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:
Hector Ventura authored and GitHub committed 2026-10-31 23:11:16 -04:00
1 parent 60500fd28d
commit 2b1d91b7ca
9 files changed
+1428 -4

No files matched your search

+11 -2
View File
@@ -44,8 +44,17 @@ trap cleanup EXIT
fail() {
echo "FAIL: $*" >&2
echo "--- floci log (last 60 lines) ---" >&2
tail -n 60 "$LOG" >&2 || true
# The first exception of a failed startup is at the top of the log and its cause chain at the
# bottom, so a long log shows both ends.
if [ "$(wc -l < "$LOG" 2>/dev/null || echo 0)" -le 200 ]; then
echo "--- floci log ---" >&2
cat "$LOG" >&2 || true
else
echo "--- floci log (first 100 lines) ---" >&2
head -n 100 "$LOG" >&2 || true
echo "--- floci log (last 100 lines) ---" >&2
tail -n 100 "$LOG" >&2 || true
fi
exit 1
}
@@ -5,6 +5,8 @@ import org.jboss.logging.Logger;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketTimeoutException;
import java.nio.file.AccessDeniedException;
import java.nio.file.NoSuchFileException;
import java.util.Locale;
/**
@@ -129,9 +131,14 @@ public final class DockerRetry {
* 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.
* Floci's startup, and each docker call of its shutdown, for about 15 seconds. A Windows named
* pipe reports the same two cases as {@link NoSuchFileException} and {@link AccessDeniedException},
* whose message is only the pipe's name.
*/
private static boolean isUnusableSocket(Throwable t) {
if (t instanceof NoSuchFileException || t instanceof AccessDeniedException) {
return true;
}
String m = t.getMessage();
if (m == null) {
return false;
@@ -0,0 +1,49 @@
package io.github.hectorvent.floci.core.common.docker;
import com.github.dockerjava.transport.NamedPipeSocket;
import java.io.IOException;
import java.net.SocketAddress;
import java.nio.channels.AsynchronousFileChannel;
import java.nio.file.AccessDeniedException;
import java.nio.file.FileSystemException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
/**
* A docker-java {@link NamedPipeSocket} that fails at once when the pipe does not exist.
*
* <p>docker-java's {@code connect} retries the open on every {@link FileSystemException} until the
* connect timeout passes, waiting for a free pipe instance in between. That wait is right for a busy
* pipe ({@code ERROR_PIPE_BUSY}), but a missing pipe, Docker not running, is never going to appear
* within the timeout: on a Windows host without Docker every Docker call spent the full 30 seconds in
* that loop, and startup never got as far as answering {@code /_floci/health}. This socket opens the
* pipe once first. A missing pipe, or one this process may not open, fails with that exception, which
* {@link DockerRetry} does not retry; any other failure, a busy pipe, falls through to docker-java's
* wait loop. When the probe opens the pipe it is closed again and docker-java opens its own channel,
* since that channel is private to {@code NamedPipeSocket}.
*/
final class FailFastNamedPipeSocket extends NamedPipeSocket {
private final String pipeName;
FailFastNamedPipeSocket(String pipeName) {
super(pipeName);
this.pipeName = pipeName;
}
@Override
public void connect(SocketAddress endpoint, int timeout) throws IOException {
try (AsynchronousFileChannel probe = AsynchronousFileChannel.open(
Paths.get(pipeName), StandardOpenOption.READ, StandardOpenOption.WRITE)) {
// The pipe exists and had a free instance; docker-java reopens it below.
} catch (NoSuchFileException | AccessDeniedException e) {
throw e;
} catch (FileSystemException expected) {
// A busy pipe, no free instance yet: docker-java's loop below waits for one, and fails
// with this same exception if none frees up within the timeout.
}
super.connect(endpoint, timeout);
}
}
@@ -166,7 +166,7 @@ public final class FlociDockerHttpClient implements DockerHttpClient {
return UnixDomainSocket.connect(path);
}
if ("npipe".equalsIgnoreCase(scheme)) {
return new NamedPipeSocket(path);
return new FailFastNamedPipeSocket(path);
}
return socksProxy == null ? new Socket() : new Socket(socksProxy);
},
@@ -214,6 +214,14 @@ public final class FlociDockerHttpClient implements DockerHttpClient {
return new FlociResponse(httpRequest, response, ttyExec && response.getCode() == 200);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (LinkageError e) {
// docker-java's named-pipe socket loads JNA when the pipe will not open. A JNA that
// cannot load (no native dispatch library for this platform) throws an Error, which
// the callers' catch (Exception) blocks would not stop, and one thrown during startup
// took down the whole emulator. As an exception it fails this one Docker call, the
// same way an unreachable daemon does.
throw new IllegalStateException("Docker's " + host.getSchemeName()
+ " transport could not load its native library: " + e, e);
}
}
@@ -0,0 +1,14 @@
{
"reflection": [
{
"condition": {
"typeReached": "com.github.dockerjava.transport.NamedPipeSocket$Kernel32"
},
"type": {
"proxy": [
"com.github.dockerjava.transport.NamedPipeSocket$Kernel32"
]
}
}
]
}
+6
View File
@@ -134,6 +134,12 @@ quarkus:
additional-build-args:
- --enable-url-protocols=http,https
- --initialize-at-run-time=io.vertx.ext.mail.impl.sasl.NTLMEngineImpl
# JNA, which docker-java's named-pipe socket loads on Windows, binds its native dispatch
# library in Native's static initializer. Initialized at build time (the Quarkus default),
# that library loads into the builder and never into the binary, so every JNA call fails
# with UnsatisfiedLinkError on Native.open. The JNI and proxy metadata JNA needs at run time
# is under META-INF/native-image/net.java.dev.jna and META-INF/native-image/io.github.hectorvent.
- --initialize-at-run-time=com.sun.jna
- --initialize-at-run-time=com.github.dockerjava.transport.NamedPipeSocket$Kernel32
- --initialize-at-run-time=io.github.hectorvent.floci.services.acm.AcmService
- --initialize-at-run-time=io.github.hectorvent.floci.services.acm.CertificateGenerator
@@ -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")));
}
}
@@ -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();
}