Prevent restore-test memory exhaustion and preserve failed-run diagnostics
Problem and user impact
A user reported host-wide memory exhaustion during an L2 restore test of an archive with about 1.92 million regular files. The Linux OOM killer terminated a running VM. The test subsequently completed, so a successful test result does not imply that the host was unaffected.
The supplied kernel log confirms global OOM at 00:29:46 on 2026-10-26. The restore-test runner PID matches the PID suffix of its per-run log and had 934014 resident pages (about 3.56 GiB at 4 KiB/page). Another unidentified Python process consumed about 5.28 GiB; its ownership cannot be established from the provided excerpt. No swap was available. The killed QEMU process had about 6.5 GiB anonymous resident memory.
Timeline: L2 begins at 00:24:45, global OOM occurs at 00:29:46, and the runner announces the complete-archive dry run only at 00:30:04. This places the observed memory failure in the archive-list preparation window. The separate scheduled failure and alleged metadata timeout are not established by this excerpt.
Findings on main at a824efb
runtime/scripts/borg_restore_test.py:_borg()captures complete stdout/stderr in memory.- L2 invokes
borg list --json-lines, callsstdout.splitlines(), and builds a Python list containing every regular file path. Sampling limits are applied only after the complete listing has been materialized. The original captured output remains referenced during the subsequent dry run. _collect_level3_legacy_pool()also captures the entire listing before selecting at most 1000 paths.- Neither the restore-test launch path nor the runner imposes a memory budget covering the runner and Borg child processes. Locks prevent concurrent access to the same repository but do not provide an aggregate memory budget across different repositories.
- The default full-dry-run threshold is 500 GiB. This archive is reported as 89.3 GiB, so a full dry run is expected despite the default 1000-file sampling limits. Lowering those limits or the threshold does not eliminate the preceding unbounded listing.
borg infouses an explicit 60-second timeout, archive listing an explicit 300-second timeout; these override the general Borg timeout setting.- Reports are overwritten at
<job_id>.test. There is no per-run restore-test report archive. Per-run text logs have timestamp/PID filenames, but the current report does not link its log. - Lifecycle events are written to the application log, not Unraid syslog; scheduled HTTP trigger output is redirected to
/dev/null. - The existing full-dry-run timeout path can report success when a preliminary sample exists. This is already documented in the user manual and must not be used as a workaround for memory pressure.
Proposed work and acceptance criteria
- Stream archive entries and retain only bounded sample data plus counters. Preserve existing coverage semantics and file-selection behavior, including L3.
- Add a configurable, enforceable memory budget for the whole restore-test process group/workload, including Borg children. Define and validate support on the actual Unraid host; do not claim protection if enforcement is unavailable. Handle concurrent tests and preserve host headroom.
- On limit exhaustion, fail the test with an actionable resource-limit reason, clean up child processes and locks, and preserve diagnostics. Do not turn interrupted checks into successful verification.
- Retain per-run reports and log associations so a retry does not destroy the preceding failure evidence. Preserve existing latest-result consumers and existing user data.
- Add useful start/end/failure diagnostics and document where scheduled-run logs can be found.
- Cover large synthetic listings with bounded-memory regression tests, listing timeouts, process cleanup, concurrent workloads, failed-run retention and retry behavior. Validate enforcement and VM/service continuity on Unraid before claiming host protection.
Scope and release notes
This is a user-visible reliability bug and needs release notes. Keep the current standalone Unraid plugin architecture. A container/host-agent redesign is outside this issue. Implementation may be split into focused follow-up issues/PRs. No production code or release artifacts were changed during the investigation.