Repository navigation
[kyo-system] fail a write that reports no progress instead of retrying - #1966
Merged
Merged
Conversation
## Problem A write that consumed zero bytes was retried with the same bytes at the same offset, so the loop could not end and the calling thread hung with no diagnostic. Four loops had no guard: both write handles and both positioned raw channels, across the NIO and Node leaves. The issue names the two handles; the raw channels beside them run the same loop against the same contract. ## Solution Each loop stops at the first write that makes no progress and fails with a new leaf, `FileWriteStalledException(path, remaining)`, which is a `FileWriteException` and so already inside every write's declared error type. A named leaf rather than `FileIOException`, because the module's guide reserves that one for failures no precise leaf describes, and because there is no platform exception here to carry as its cause. Not a panic: nothing the caller did produces it. Bounding the retry count instead, the issue's other suggestion, only moves the stall, since a bounded loop that gives up still has to report this. ## Notes Each reproduction drives a write that takes no bytes and asserts it was attempted exactly once, which is what proves the retry is gone. The stubs throw past a small call bound so a regression fails on the count rather than hanging the suite. The new leaf is public surface under `FileWriteException`, so a wildcard-free exhaustive match on that trait now warns. `FileSystemExceptionTest` keeps such a match deliberately, as the alarm for exactly this. The `kyo-net` loops that also test `hasRemaining` are untouched and are not defects: a zero-byte return there is the documented want-write signal, already routed to a `WriteResult`. Green on JVM, JS, Wasm and Native. Fixes #1848
fwbrasil
force-pushed
the
fix/kyo-system-write-progress
branch
from
September 20, 2026 13:54
28b9829 to
4bc6864
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1848
Problem
A short write is ordinary: a platform write call may take fewer bytes than offered, and the remainder is re-offered from where it stopped. Zero bytes taken is not a short write. The retry offers the same bytes at the same offset, gets the same answer, and the loop cannot end, so the calling thread hangs with no diagnostic.
Four loops had no progress guard:
NioWriteHandle.writeBytes,while buf.hasRemaining do discard(channel.write(buf))NioRawChannel.writeAt,while buf.hasRemaining do written += channel.write(buf, pos + written)NodeWriteHandle.writeBytes, tail-recursiveloop(offset + writeSync(...))NodeRawChannel.writeAt,written += writeSync(..., pos + written)The issue names the two write handles. The two positioned raw channels beside them run the same loop against the same contract, so guarding only two of them would be a divergence of its own.
Solution
Each loop stops at the first write that reports no progress and fails with a new leaf of the filesystem error hierarchy:
A named leaf rather than
FileIOException: the module's guide reservesFileIOExceptionfor a failure no more precise leaf describes, and this one is precise. It also has no diagnostic cause to carry, since no platform exception is thrown, so reporting it as an I/O error meant inventing anIOExceptionto fill that field. A caller can now match the condition rather than parse a message, andremaininggives it the unwritten count, as aByteSizefor the same reasonFileLockTimeoutExceptiontakes aDuration.Not a panic: nothing the caller did produces this, it is already inside the declared
FileWriteExceptionof every write, so no signature and no caller changes, and the caller's ordinary write-failure handling is where it belongs.Bounding the retry count, the issue's other suggestion, only moves the stall: a bounded loop that gives up still has to report something, and the something is this failure. Guarding at the first zero-byte return is the same report without the spin.
The four loops keep their own shapes, the buffer-cursor form on JVM and Native and the offset form on JavaScript and Wasm, positioned and unpositioned.
Notes
Four leaves, two per platform source set, each asserting both the failure and its
remaining, and that the platform write was attempted exactly once, which is what proves there is no retry:jvm-native/src/test/scala/kyo/internal/PathPlatformSpecificTest.scala, aFileChannelsubclass whose write overloads count their calls, return 0, and throw past a small bound so a regression cannot hang the suite. It sits injvm-native, so JVM and Native run the same file.js/src/test/scala/kyo/internal/PathPlatformSpecificJsTest.scala, patchingfs.writeSyncfor the duration of the leaf and restoring it infinally. JS only, because Wasm links as an ES module whose namespace is sealed and cannot be patched; the file records that.FileSystemExceptionTestcarries the new leaf in its field-retention list and its category assertions, and in the exhaustiveFileWriteExceptionmatch, which has no wildcard precisely so that a new subtype cannot be added without being accounted for there.The
kyo-netloops that also testhasRemainingare untouched and are not defects: those are non-blocking socket writes where a zero-byte return is the documented want-write signal, and each already routes it to aWriteResultrather than retrying.Green on JVM, JS, Wasm and Native (584 kyo-system tests on Native, 574 on Wasm, 608 on JS), plus the kyo-system README doctest.