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

@@ -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);
}
}