Skip to content

NAR: a failed withNarSource pull stays failed, as the codec sources' do - #105

Merged
aoinoikaz merged 1 commit into
mainfrom
nar-stream-latch
Nov 16, 2026
Merged

aoinoikaz merged 1 commit into
mainfrom
nar-stream-latch

Conversation

@aoinoikaz

@aoinoikaz aoinoikaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

A NAR source stream that failed because a file shrank mid-read marked itself drained, so the next pull returned the empty chunk, the clean-end signal, and a consumer that caught the failure and pulled again took a truncated archive for a complete one. Any exception a pull lets escape is now latched and rethrown by every later pull, as the zstd, xz and bzip2 sources do, and the latch closes the stream's open handle. An exception raised while a pull runs is latched; an asynchronous exception delivered after a pull has returned can still escape unlatched, so a consumer must not resume a source after one. A pull after a failed open, which used to retry the file, rethrows the failure too, the same rule for every failure.

Closes #103.

A pull that found a file shorter than the size it had read marked the
source drained before it threw, so the next pull returned the empty
chunk that marks a clean end, and a consumer that caught the failure
and pulled again took a truncated archive for a complete one. Any
other failure left the state where it was, so the next pull carried
on from there.

Any exception raised while a pull runs now latches as SourceFailed
and is rethrown by every later pull, as NovaCache.Xz, NovaCache.Zstd
and NovaCache.Bzip2 latch theirs. It is held at SomeException, as
theirs are, because a pull interrupted after its read consumed bytes
it never returned leaves the archive as torn as a failed one. The
latch closes the file the state held, and only the pull itself runs
unmasked, so no asynchronous exception can fall between a failure and
its latch or leave the file open. One that arrives as a successful
pull returns is not latched, since the state has already moved past
the chunk it loses, so the documentation tells a consumer not to pull
again after an asynchronous exception. The shrink path no longer
closes the file or writes the state itself; the latch does both.

One test cuts a file short after its size is read and checks the
failing pull and the two after it; another fails a file's open, makes
the file readable again and pulls once more. Both run on POSIX.
@aoinoikaz
aoinoikaz merged commit 7899c02 into main Nov 16, 2026
12 checks passed
@aoinoikaz
aoinoikaz deleted the nar-stream-latch branch November 16, 2026 05:42
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.

NAR: a source stream that failed reads as a clean end on the next pull

1 participant