diff --git a/dist/urbm-2026.10.15.r001-x86_64-1.txz b/dist/urbm-2026.10.15.r001-x86_64-1.txz new file mode 100644 index 0000000..a7fafc3 Binary files /dev/null and b/dist/urbm-2026.10.15.r001-x86_64-1.txz differ diff --git a/dist/urbm-2026.10.15.r001-x86_64-1.txz.sha256 b/dist/urbm-2026.10.15.r001-x86_64-1.txz.sha256 new file mode 100644 index 0000000..8b7fa20 --- /dev/null +++ b/dist/urbm-2026.10.15.r001-x86_64-1.txz.sha256 @@ -0,0 +1 @@ +e4a9906820384c0bff708c02d81a8915b7d5e034984052e42bf7c09761a47a31 urbm-2026.10.15.r001-x86_64-1.txz diff --git a/dist/urbm.plg b/dist/urbm.plg index c2430d3..15c72b1 100644 --- a/dist/urbm.plg +++ b/dist/urbm.plg @@ -2,13 +2,18 @@ - + - + ]> +### 2026.10.15.r001 +- Parse carriage-return progress updates during Rsync space estimation instead of accumulating oversized lines. +- Share the streaming parser with the copy runner and report output-read failures without blocking the child process. +- Cover multi-megabyte progress output, mixed line endings and oversized-token draining with synthetic regression tests. + ### 2026.10.09.r001 - Estimate additional Rsync destination space separately from transfer volume. - Account for replacement files, sparse allocation, temporary copies and a safety reserve; never credit delayed deletions early. diff --git a/docs/rsync-progress-parser-2026-10-15.md b/docs/rsync-progress-parser-2026-10-15.md new file mode 100644 index 0000000..f874454 --- /dev/null +++ b/docs/rsync-progress-parser-2026-10-15.md @@ -0,0 +1,29 @@ +# Rsync preflight Scanner failure + +Rsync `--info=progress2` updates can be separated by carriage returns rather than +newlines. Estimate previously used Scanner's default ScanLines, so enough +updates formed a token larger than its configured 2 MiB maximum. The preflight +then correctly refused to proceed with an unknown estimate, but users could +mistake the error for insufficient destination capacity. + +Estimate now shares the copy runner's CR/LF-aware streaming parser. The common +parser returns read errors and drains the remaining pipe after a parse failure, +preventing a blocked producer. Run now propagates these errors instead of +silently returning a potentially incomplete summary. The token bound remains +2 MiB; free-space checks and deletion/overwrite settings are unchanged. + +Synthetic regression: 100,000 CR-delimited progress updates followed by zero-file +summary statistics. The previous source fails with `SpaceUnknown: bufio.Scanner: +token too long`; the fixed source returns a known zero-byte estimate. Additional +tests cover mixed CR/LF with an unterminated final line and oversized-token error +reporting/draining. Existing real-rsync tests use temporary synthetic files only. +No production backup data, configuration or logs were inspected or replayed. + +Validation: all Go packages passed on Linux with Go 1.27.2 and system rsync; +`go vet ./...`, shell syntax, migration fixture and JavaScript syntax passed. +An initial full run exposed an unrelated intermittent Restic BackupImage summary +test failure; that test passed three immediate repeats and the full rerun. +This change does not fix or claim to resolve that separate Restic behavior. + +Release 2026.10.15.r001 contains the fix. Publishing an update does not validate +available capacity for a real job; the next real preflight still must succeed. diff --git a/internal/rsync/rsync.go b/internal/rsync/rsync.go index 1d58e00..b38ce18 100644 --- a/internal/rsync/rsync.go +++ b/internal/rsync/rsync.go @@ -91,9 +91,10 @@ func (r *Runner) Run(ctx context.Context, runID string, job model.Job, callback defer unregister() var summary Summary + var scanErr error done := make(chan struct{}) go func() { - scanOutput(stdout, func(line string) { + scanErr = scanOutput(stdout, func(line string) { summary.parseLine(line) if callback != nil { if progress, ok := parseProgress(line); ok { @@ -121,6 +122,9 @@ func (r *Runner) Run(ctx context.Context, runID string, job model.Job, callback } return Summary{}, fmt.Errorf("rsync: %s", message) } + if scanErr != nil { + return summary, fmt.Errorf("rsync output: %w", scanErr) + } return summary, nil } @@ -176,16 +180,11 @@ func (r *Runner) Estimate(ctx context.Context, runID string, job model.Job) (Sum space := newSpaceEstimate(job.Rsync.Target) done := make(chan struct{}) go func() { - scanner := bufio.NewScanner(stdout) - scanner.Buffer(make([]byte, 64*1024), 2*1024*1024) - for scanner.Scan() { - line := scanner.Text() + if err := scanOutput(stdout, func(line string) { summary.parseLine(line) space.consume(line) - } - if err := scanner.Err(); err != nil { + }); err != nil { space.problem = err.Error() - _, _ = io.Copy(io.Discard, stdout) } close(done) }() @@ -282,7 +281,7 @@ func (r *Runner) register(runID string, process *os.Process) func() { } } -func scanOutput(reader io.Reader, callback func(string)) { +func scanOutput(reader io.Reader, callback func(string)) error { scanner := bufio.NewScanner(reader) scanner.Split(splitLinesAndCarriageReturns) scanner.Buffer(make([]byte, 64*1024), 2*1024*1024) @@ -291,6 +290,12 @@ func scanOutput(reader io.Reader, callback func(string)) { callback(line) } } + if err := scanner.Err(); err != nil { + // Keep draining so rsync cannot block on a full stdout pipe before Wait. + _, _ = io.Copy(io.Discard, reader) + return err + } + return nil } func drainLimited(reader io.Reader, limit int) []byte { diff --git a/internal/rsync/rsync_test.go b/internal/rsync/rsync_test.go index c427699..62195c0 100644 --- a/internal/rsync/rsync_test.go +++ b/internal/rsync/rsync_test.go @@ -7,6 +7,7 @@ import ( "slices" "strings" "testing" + "time" "git.casaderoll.de/michael/urbm/internal/model" ) @@ -170,3 +171,43 @@ func TestRealRsyncDryRunAndCopy(t *testing.T) { t.Fatalf("identical: %+v %v", identical, err) } } + +// progress2 updates use CR without LF; a long comparison must not accumulate +// them into one multi-megabyte Scanner token or hide its final statistics. +func TestEstimateHandlesLongCarriageReturnProgress(t *testing.T) { + dir := t.TempDir() + output := filepath.Join(dir, "output") + progress := strings.Repeat(" 1,234,567 42% 12.34MB/s 0:00:05\r", 100000) + if err := os.WriteFile(output, []byte(progress+"\nNumber of regular files transferred: 0\nTotal transferred file size: 0 bytes\n"), 0600); err != nil { + t.Fatal(err) + } + binary := filepath.Join(dir, "rsync") + if err := os.WriteFile(binary, []byte("#!/bin/sh\ncat '"+output+"'\n"), 0700); err != nil { + t.Fatal(err) + } + runner := Runner{Binary: binary} + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + got, err := runner.Estimate(ctx, "cr-progress", model.Job{Rsync: model.RsyncOptions{Target: dir}}) + if err != nil || got.SpaceUnknown != "" || got.Files != 0 || got.Bytes != 0 || got.RequiredBytes != 0 { + t.Fatalf("summary=%+v err=%v", got, err) + } +} + +func TestScanOutputMixedDelimitersAndFinalLine(t *testing.T) { + var got []string + err := scanOutput(strings.NewReader("one\rtwo\r\nthree\nfour"), func(s string) { got = append(got, s) }) + if err != nil || !slices.Equal(got, []string{"one", "two", "three", "four"}) { + t.Fatalf("lines=%v err=%v", got, err) + } +} + +func TestScanOutputReportsOversizedTokenAndDrains(t *testing.T) { + input := strings.NewReader(strings.Repeat("x", 3*1024*1024) + "\nremaining\n") + if err := scanOutput(input, func(string) {}); err == nil { + t.Fatal("oversized output silently accepted") + } + if input.Len() != 0 { + t.Fatalf("stdout not drained: %d bytes", input.Len()) + } +} diff --git a/plugin/urbm.plg b/plugin/urbm.plg index 31323a7..ea05da5 100644 --- a/plugin/urbm.plg +++ b/plugin/urbm.plg @@ -2,13 +2,18 @@ - + ]> +### 2026.10.15.r001 +- Parse carriage-return progress updates during Rsync space estimation instead of accumulating oversized lines. +- Share the streaming parser with the copy runner and report output-read failures without blocking the child process. +- Cover multi-megabyte progress output, mixed line endings and oversized-token draining with synthetic regression tests. + ### 2026.10.09.r001 - Estimate additional Rsync destination space separately from transfer volume. - Account for replacement files, sparse allocation, temporary copies and a safety reserve; never credit delayed deletions early. diff --git a/webgui/URBM.page b/webgui/URBM.page index 74be9e6..d70d9ce 100644 --- a/webgui/URBM.page +++ b/webgui/URBM.page @@ -8,7 +8,7 @@ Tag="URBM Unraid Restic Backup Manager backup snapshots restore" ---