Skip to content

Report interrupted stream reads of cancelled flows as cancellation - #911

Open
gesellix wants to merge 1 commit into
mainfrom
fix/cancelled-stream-reads
Open

gesellix wants to merge 1 commit into
mainfrom
fix/cancelled-stream-reads

Conversation

@gesellix

@gesellix gesellix commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #908, which made blocking stream reads cancellable via runInterruptible.

Problem

When a stream flow is cancelled, e.g. by the timeout of containerStats, runInterruptible interrupts the reading thread. Socket implementations report that interrupt as an IOException (InterruptedIOException for named pipes, ClosedByInterruptException for channels). runInterruptible only translates InterruptedException into a cancellation, so callers saw a failed read instead of the expected end of the stream.

That's why containerStatsStream fails on Windows CI:

java.io.InterruptedIOException: Read interrupted
    at de.gesellix.docker.client.filesocket.NamedPipeSocket$TimeoutAwareInputStream.read(NamedPipeSocket.java:234)
    ...
    at de.gesellix.docker.response.JsonChunksReader.hasNext(JsonChunksReader.java:37)
    ...
    at kotlinx.coroutines.InterruptibleKt.runInterruptible(Interruptible.kt:39)

Change

A shared readInterruptible helper runs the read via runInterruptible on Dispatchers.IO. If the read fails with an IOException after the coroutine was cancelled, the cancellation is reported instead. Without a cancellation, every IOException (including SocketTimeoutException) is rethrown unchanged. consumeStream and both consumeFrames use the helper.

Tests

Locally against Docker Desktop with Windows containers:

  • containerStatsStream fails on main and passes with this change.
  • The non-streaming stats test passes, and so do the logs, attach, exec and systemEvents streaming tests.

🤖 Generated with Claude Code

Since stream reads run via runInterruptible, cancelling a flow (e.g. the
timeout of containerStats) interrupts the reading thread. Socket
implementations report that as an IOException (InterruptedIOException for
named pipes), which runInterruptible doesn't translate into a
cancellation, so callers saw a failed read instead of the expected end of
the stream (containerStatsStream failed on Windows).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

 64 files  + 32   64 suites  +32   8m 20s ⏱️ + 5m 47s
270 tests + 22  251 ✅ + 17  16 💤 + 2  3 ❌ +3 
491 runs  +243  452 ✅ +218  36 💤 +22  3 ❌ +3 

For more details on these failures, see this check.

Results for commit ab2332b. ± Comparison against base commit 7b9154a.

♻️ This comment has been updated with latest results.

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