Skip to content

Lock the queue when a persist write fails (#161) - #164

Merged
jonbaldie merged 1 commit into
mainfrom
fix/161-failed-persist-leaves-queue
Oct 10, 2026
Merged

jonbaldie merged 1 commit into
mainfrom
fix/161-failed-persist-leaves-queue

Conversation

@jonbaldie

Copy link
Copy Markdown
Owner

Closes #161

Summary

enqueue / dequeue
  write the log first
  if the write throws
    return 500
    leave the in-memory queue unchanged
  then push or shift

#163 already persists before mutating memory. That is why a full PERSIST volume no longer delivers rejected items or drops a dequeued item. Nothing locked the case where the log is already at the size cap, so a later reorder would bring #161 back. This adds that regression test.

Evidence

  • Before: With memory changed before saveEvent, the same loop went red: dequeue at cap -> 500 length 1 -> 0, then a rejected enqueue stayed queued (length=1).
    After: deno test --allow-all tests/short_write_test.ts --filter '#161' passes. On a 2 MiB HFS+ RAM disk filled to the allocation-block boundary, dequeue and enqueue both return 500 with No space left on device (os error 28) and length stays 1; after space is freed the accepted item is delivered.

Merge Danger

Door: two-way

Test-only. Revert the commit to drop the lock; runtime behaviour is unchanged.

Blast Radius: tests

The new test starts a real server under ulimit -f, the same seam as the #160 short-write tests.

Enqueue and dequeue already write the log before changing memory (#163).
A failed write therefore returns 500 and leaves the queue unchanged.
Nothing covered a write that fails outright once persist.dat is already
at the size cap, so reversing that order would again drop an item on a
500 dequeue and keep a rejected enqueue.

The regression test fills the log to the ulimit cap, then checks that a
500 dequeue and a 500 enqueue leave length unchanged and that only the
accepted item is recovered after restart.
@jonbaldie
jonbaldie merged commit bef9aa5 into main Oct 10, 2026
4 checks passed
@jonbaldie
jonbaldie deleted the fix/161-failed-persist-leaves-queue branch October 10, 2026 08:30
@jonbaldie jonbaldie mentioned this pull request Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enqueue/dequeue return 500 when the persist write fails but have already changed the queue (rejected items delivered, dequeued items lost)

1 participant