Skip to content

fix(target/queue): Clean up dangling entries when meta file is missing - #901

Open
amalsaidov wants to merge 1 commit into
foxcpp:masterfrom
amalsaidov:fix/queue-deserialization-nometa
Open

amalsaidov wants to merge 1 commit into
foxcpp:masterfrom
amalsaidov:fix/queue-deserialization-nometa

Conversation

@amalsaidov

@amalsaidov amalsaidov commented Nov 11, 2026 •

Copy link
Copy Markdown

Fixes #209.

What

readDiskQueue walked only .meta files to decide what to load and what to clean up. If a messages .meta file was gone but its .header and .body files were still on disk, that entry was never looked at, so the two leftover files stayed in the queue directory forever.

This rewrites the scan to group all queue files by message ID first. An entry is treated as dangling when any of its three files (.meta, .header, .body) is missing, and whatever files remain are removed. Complete entries are loaded exactly as before.

Why

Partial writes and partial removals can leave any one of the three files missing, not just .header or .body. The old meta-first scan could not recover from a missing .meta, so those orphans accumulated on disk.

Tested

The NoMeta sub-test of TestQueueDelivery_DeserlizationCleanUp covered exactly this case but was skipped with t.Skip("Not implemented"). I removed the skip, and the fix makes it pass alongside the existing NoBody and NoHeader sub-tests.

  • go test ./internal/target/queue/... passes, including all three DeserlizationCleanUp sub-tests
  • go vet ./internal/target/queue/... clean
  • gofmt -l reports no changes on the touched files
  • go build ./... builds cleanly for every package except cmd/maddy-pam-helper, which fails to compile its C code on my local macOS clang over an unrelated -Wstrict-prototypes warning and is untouched by this change

Assisted-By: Claude Opus 4.8 (Claude Code)

readDiskQueue scanned only .meta files, so an entry whose .meta was
removed but still had .header and .body left those two files on disk
forever. They were never iterated and never cleaned up.

Group all queue files by message ID first and treat an entry as dangling
whenever any of the three files (.meta, .header, .body) is missing, then
remove whatever is left. Complete entries are loaded as before.

This enables the previously skipped NoMeta sub-test of
TestQueueDelivery_DeserlizationCleanUp.

Fixes foxcpp#209.

Assisted-By: Claude Opus 4.8 (Claude Code)
Signed-off-by: amalsaidov <amalsaidov@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: First Feedback Needed

Development

Successfully merging this pull request may close these issues.

Rewrite queue deserialization to pass all tests in DeserializationCleanUp

1 participant