Repository navigation
Keep the last good state files when a save fails (ENOSPC); retry it; no clean stop while saves fail - #748
Draft
xbmc4lyfe wants to merge 3 commits into
Draft
Keep the last good state files when a save fails (ENOSPC); retry it; no clean stop while saves fail#748xbmc4lyfe wants to merge 3 commits into
xbmc4lyfe wants to merge 3 commits into
Conversation
…stop while saves fail On 6790 the queue disk filled (ENOSPC). The partial state of the downloading file (<id>s) was written in place, the failed write cut it short, the restart found it damaged and discarded every article it recorded: 57 GB downloaded again. - Every state file, also <id>s/<id>c, is written to <file>.new and renamed; a write or a sync that fails (ENOSPC, EIO, EDQUOT) deletes the .new and keeps the last good file. The file is no longer deleted before the rename. - statesaver: a failed save stays queued and is retried with backoff (1 s doubling to 30 s); a newer save of the file takes its place and backoff; no caller waits for a failing save. At the stop each gets a last attempt; a still failing one is given up, logged at ERROR, and the process exits 1. - A queue save deletes progress only after the queue file reached the disk (a delete that waits for another file's write), never while it fails. - Scenario diskfullrestart: QueueDir/InterDir on a small ext4 (Linux, sudo loop mount) or HFS+ image (macOS), filled at 40 %, stop, free, restart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
Syncing every <id>s save (and its directory) queued the per-second saves of all downloading files behind one another on the saver thread; a thread that waits for its save under the queue lock waited seconds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
…k, .new handling - drain gives failed saves their last attempt one at a time, recorded in last_attempt in the same hold, so a delete waiting for that file never runs before the attempt is decided. - Without a saver thread, drain and wait_for run the due jobs inline; a failed inline job no longer stops the others and merges into a newer one. - The worker sleeps only for retries it could run. - Tickets only under the queue lock. - remove_queue_file deletes <file>.new too; the state loader skips names with a dot (a <id>s.new is read through its <id>s). - The unclean-stop flag is decided by each teardown. - diskfullrestart: stop must exit 1 with the unclean log, 4 s margin, lazy unmount fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM
This branch has not been deployed
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.
Why
On 6790 (2026-11-27 02:56Z) the NVMe holding QueueDir and InterDir filled up. At the 20:56 CST stop the partial state of the downloading file,
334597s(Uncut Gems UHD #2466, one 90 GB file of 126,649 articles), was written in place. The failed write cut it short. After the restart the load loggedError reading diskstate for file 334597andDiscarding damaged download state 334597s, so every article it recorded was dropped: RemainingSizeMB went from 27434 to 85139, and about 57 GB was downloaded again. Thequeue,files,progressandstatssaves failed too, and the queue save still deletedprogress.What restores per-file progress is
<id>s(each article's status, offset, size and crc).progressholds only NZB-level counters. The current NZB counters (remaining size and the rest) are recomputed from the file states at load (UpdateCurrentStats), so a staleprogresscosts only counters, never a download. The state RustyGet already keeps is therefore enough, as long as a failed write can never destroy it.What changes
<id>s/<id>c, is written to<file>.newand renamed. If the write fails, or a sync fails with ENOSPC, EIO or EDQUOT, the.newis deleted, the old file stays and the save fails. The file is no longer deleted before the rename: rename(2) replaces it in one step. Partial states stay unsynced, as before. Syncing each one, plus its directory, queued the per-second saves of every downloading file behind each other (queuesyncslow regressed).statesaver). Each attempt is logged at ERROR. A failed save stays queued and is retried with backoff (1 s, doubling to 30 s). A newer save of the same file takes its place and its backoff. No caller waits for a failing save, so the API and the coordinator are not stalled by a full disk. A success after failures logsSaved diskstate file X after N failed attempts.progressis deleted only after the queue save is on disk. This uses a delete that waits for another file's write (Delete { after }). The delete never runs while the queue save fails, and it is dropped if that save is given up.Stopping is not clean: N state file(s) could not be saved ...(ERROR), and the process exits 1. systemd then reports a failure instead of "Deactivated successfully".<id>s.newentries; such a file is read through its<id>s.remove_queue_filealso deletes the.new.Scenario
diskfullrestartQueueDir and InterDir sit on a small file system of their own: a 64 MB ext4 image, loop-mounted with
sudo -non Linux, or an HFS+ image through hdiutil on macOS. ext4 frees a truncated file's blocks only at the next journal commit, as the 6790 NVMe did. With ContinuePartial=yes, FlushQueue=yes and DiskSpace=0:The scenario asserts that no article fetched before the fill (less the last 4 s) is fetched again, counted by message-id from nserv's request log. It also asserts that the output is byte-exact, that save errors were logged, and that the stop exited 1 with the unclean log.
origin/mainplus the scenario only (23716162), x86_64: FAIL (timeout waiting for RelDF in history; rerun alone: FAIL).PASS status=SUCCESS integrity=True recorded_before_fill=131 fetched_again=0 ... save_errors=15 stop_rc=1 unclean_logs=1 discarded_states=0. arm64: the same, with 130 recorded and 0 fetched again.Not in this PR (follow-up)
The 6790 journal also shows 2628
Could not commit cached article ... No space left on device.article_writer_flush_cache_guardedcounts and discards a cached article whose write failed, while the article stays done in the state, so the output gets a hole. Keeping the item cached would block the stop: the cache thread exits only when the cache is empty, and theacacheflag would drop every partial state. That needs its own design, recorded in rustyget-next-prs.md.Validation
Farm gate on head 115cb37 (job farm-val-115cb37e-179575184336p8; GitHub Actions unavailable, farm runs replace it):
diskfullrestart on the head (x86_64 and arm64 PASS):
Control: the same scenario on main 7bef261 plus the scenario only (23716162) FAILS on x86_64 (timeout waiting for RelDF; rerun alone FAIL).
GitHub Actions is unavailable; the farm runs replace it. macOS: not required (no platform-specific code; the scenario's macOS branch uses hdiutil).
🤖 Generated with Claude Code
https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM