Skip to content

Stabilize Windows named pipe sockets (WCOW) - #526

Merged
gesellix merged 4 commits into
mainfrom
fix/named-pipe-wcow-stability
Dec 3, 2026
Merged

gesellix merged 4 commits into
mainfrom
fix/named-pipe-wcow-stability

Conversation

@gesellix

@gesellix gesellix commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Fixes hangs, lost data and broken timeouts in the Windows named pipe transport, and makes both named pipe implementations selectable so they can be compared.

Changes

NamedPipeSocket (default; built on AsynchronousFileChannel)

  • setSoTimeout() is honored now; the previous Channels.newInputStream() blocked without any timeout.
  • A timed-out read stays pending and the next read() continues with it. No data gets lost, the caller's array isn't written to after read() returned, and there's never more than one read in flight.
  • isConnected()/isBound() report the actual state; shutdownOutput()/shutdownInput() are no-ops (named pipes have no half-close). OkHttp needs this to finish writing to hijacked attach/exec streams.
  • connect() honors the caller's timeout (0 = infinite) and throws SocketTimeoutException.

NamedPipeJniSocket / NamedPipeUtils (overlapped I/O via JNA)

  • Overlapped reads/writes use native Memory buffers. JNA only keeps a byte[] valid during the call itself, so pending I/O read from or wrote into released memory.
  • The OVERLAPPED struct is passed as a raw pointer. Passing the Structure let JNA write its stale fields (Internal=STATUS_PENDING) back before GetOverlappedResult, which caused ERROR_IO_INCOMPLETE or hangs.
  • soTimeout 0 means "wait indefinitely" instead of "don't wait".
  • Waits can be interrupted. docker-remote-api-client cancels blocking attach/exec reads via Thread.interrupt(); a native WaitForSingleObject ignored that and hung.
  • Partial writes continue at the right offset; data of a read completing right before a timeout is kept.
  • IOException/SocketTimeoutException instead of RuntimeException; same Socket overrides as NamedPipeSocket.

NamedPipeSocketFactory

  • Selects the implementation via constructor, system property de.gesellix.docker.client.filesocket.namedpipe.impl (channel|jni) or env var DOCKER_FILESOCKET_NAMEDPIPE_IMPL. Default stays channel.

Tests

  • NamedPipeImplementationsTest: the same scenarios against both implementations, using an in-process pipe server (no Docker needed): pending reads/writes with data verification, read timeout without data loss, half-close, interrupt, close during a pending read.
  • Verified that the new tests fail or hang against the previous code.
  • WCOW (Docker Desktop, Windows containers), both implementations, using a local snapshot of this branch:
    • docker-remote-api-client: attach (interactive/non-interactive), exec (interactive/non-interactive), logs.
    • docker-client: attach (interactive), exec (interactive), http over named pipe, diff (together with test fixes in docker-client).

🤖 Generated with Claude Code

gesellix and others added 4 commits December 3, 2026 21:52
…EOF handling

- NamedPipeSocket: timeout-aware streams on top of the async channel,
  honor connect timeout, report isConnected/isBound, no-op half-close
- NamedPipeJniSocket: mutable soTimeout shared with source/sink, pass
  connect timeout through
- NamedPipeUtils: throw IOException/SocketTimeoutException instead of
  RuntimeException, classify read/write errors at the call site, drain
  cancelled overlapped I/O before returning

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… timeout

- pass a JNA Memory buffer instead of byte[] to overlapped ReadFile/WriteFile:
  JNA only keeps a byte[] valid during the call, so pending I/O read from or
  wrote into released memory
- pass the OVERLAPPED as raw pointer: passing the Structure made JNA write
  its stale fields (Internal=STATUS_PENDING) back before GetOverlappedResult,
  causing ERROR_IO_INCOMPLETE (bWait=false) or a hang (bWait=true)
- map soTimeout 0 to INFINITE for WaitForSingleObject instead of "don't wait"
- resume partial writes at the current offset instead of resending from 0
- keep data of a read that completed right before a timeout cancellation
- add in-process pipe tests forcing pending reads/writes and soTimeout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oss timeouts

- NamedPipeSocketFactory: choose NamedPipeSocket (CHANNEL, default) or
  NamedPipeJniSocket (JNI) via constructor, system property
  de.gesellix.docker.client.filesocket.namedpipe.impl or env var
  DOCKER_FILESOCKET_NAMEDPIPE_IMPL
- NamedPipeSocket: read into an internal buffer and keep a timed-out read
  pending for the next read() instead of losing its data, writing into the
  caller's array later, or running two reads concurrently; fail cleanly when
  not connected or closed
- NamedPipeJniSocket: isBound/shutdownOutput/shutdownInput like NamedPipeSocket
- NamedPipeImplementationsTest: the same in-process pipe scenarios for both
  implementations, replacing the JNI-only tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WaitForSingleObject can't be interrupted from Java, so a read without
soTimeout ignored Thread.interrupt(). docker-remote-api-client relies on
interrupts (runInterruptible) to cancel blocking attach/exec frame reads,
which made attach (interactive) hang with the JNI implementation on WCOW.
Wait in 100ms slices, and cancel and drain the I/O when interrupted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gesellix
gesellix merged commit c7d0518 into main Dec 3, 2026
5 of 6 checks passed
@gesellix
gesellix deleted the fix/named-pipe-wcow-stability branch December 3, 2026 21:53
gesellix added a commit to gesellix/docker-client that referenced this pull request Dec 3, 2026
Named pipe fixes for WCOW (docker-client/docker-filesocket#526) and
UnixSocket timeout/half-close delegation (docker-client/docker-filesocket#527).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gesellix added a commit to docker-client/docker-remote-api-client that referenced this pull request Dec 3, 2026
Named pipe fixes for WCOW (docker-client/docker-filesocket#526) and
UnixSocket timeout/half-close delegation (docker-client/docker-filesocket#527).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gesellix added a commit to docker-client/docker-remote-api-client that referenced this pull request Dec 3, 2026
Named pipe fixes for WCOW (docker-client/docker-filesocket#526) and
UnixSocket timeout/half-close delegation (docker-client/docker-filesocket#527).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gesellix added a commit to gesellix/docker-client that referenced this pull request Dec 3, 2026
Named pipe fixes for WCOW (docker-client/docker-filesocket#526) and
UnixSocket timeout/half-close delegation (docker-client/docker-filesocket#527).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant