Return errors instead of exiting on rollback, rows close and blob temp file cleanup #364

Merged
clawbot merged 1 commits from issue-345-no-process-exit into next 2026-10-13 19:46:49 +02:00
Collaborator

Fixes #345.

What was wrong: three failures ended the process, skipping deferred cleanup: a failed rollback in WithReadTx (including after Ctrl-C, when the rollback finds the transaction already rolled back), a failed close of query results in internal/database, and a failed close or remove of a blob's temp file in the upload step.

What changed:

  • WithReadTx handles its rollback exactly as WithTx does since #301.
  • The query functions close their rows with defer func() { _ = rows.Close() }(). This loses nothing: each reads its rows to the end, where database/sql closes them itself and returns any close failure from rows.Err(), which each already returns (the Rows.Close documentation says so). The deferred close only does work on paths already returning an error. database.Fatalf had no callers left and is removed.
  • cleanupBlobTempFile returns its close or remove failure, and handleBlobReady returns it, joined with the upload or metadata error when there is one. When the close fails the remove is skipped, but the packer closes and removes the temp file itself whenever the upload step returns an error.

Judgement call: a temp file that cannot be closed or removed after a successful upload now fails the backup with that error, where it used to end the process, rather than being logged and skipped.

Not tested: no test makes closing query results fail; the SQLite driver fails that close only with the error the last read already returned.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/vaultik/issues/345. **What was wrong:** three failures ended the process, skipping deferred cleanup: a failed rollback in `WithReadTx` (including after Ctrl-C, when the rollback finds the transaction already rolled back), a failed close of query results in `internal/database`, and a failed close or remove of a blob's temp file in the upload step. **What changed:** - `WithReadTx` handles its rollback exactly as `WithTx` does since https://git.eeqj.de/sneak/vaultik/issues/301. - The query functions close their rows with `defer func() { _ = rows.Close() }()`. This loses nothing: each reads its rows to the end, where `database/sql` closes them itself and returns any close failure from `rows.Err()`, which each already returns (the `Rows.Close` documentation says so). The deferred close only does work on paths already returning an error. `database.Fatalf` had no callers left and is removed. - `cleanupBlobTempFile` returns its close or remove failure, and `handleBlobReady` returns it, joined with the upload or metadata error when there is one. When the close fails the remove is skipped, but the packer closes and removes the temp file itself whenever the upload step returns an error. Judgement call: a temp file that cannot be closed or removed after a successful upload now fails the backup with that error, where it used to end the process, rather than being logged and skipped. Not tested: no test makes closing query results fail; the SQLite driver fails that close only with the error the last read already returned. Model: opus-5-5
clawbot added the needs-review label 2026-10-13 17:43:14 +02:00
clawbot self-assigned this 2026-10-13 17:43:14 +02:00
clawbot added 1 commit 2026-10-13 17:43:14 +02:00
WithReadTx ended the process when its rollback failed, including after
Ctrl-C, when database/sql has already rolled the transaction back and
Rollback returns sql.ErrTxDone. It now handles the rollback as WithTx
does. The query functions ended the process when closing their rows
failed; they now ignore the deferred close, because database/sql reports
a close failure through rows.Err(), which each returns, once the rows
are read to the end. The unused database.Fatalf is removed.
cleanupBlobTempFile returns its close or remove failure and the upload
step returns it, so such a failure now fails the backup.

No test makes a rows close fail: SQLite fails it only with the error the
last read already returned.

Model: opus-5-5
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit 3b2b9cec84 into next 2026-10-13 19:46:49 +02:00
clawbot deleted branch issue-345-no-process-exit 2026-10-13 19:46:49 +02:00
Sign in to join this conversation.