Skip to content

Conversation

harrytmthy
Copy link
Owner

Summary

Fixes a rare but critical issue where overlapping .apply() and .commit() operations on the same SafeBox instance could cause data corruption or AEADBadTagException. The root cause was concurrent writes to the underlying blob store, especially when commit() arrived before a prior apply() had finished persisting to disk.

Implementation Details

This patch introduces serialized write sequencing via a per-instance writeBarrier: AtomicReference<CompletableDeferred<Unit>>. Each new write operation, from either .apply() or .commit(), will now:

  • Wait for the previous write to complete (previousWriteBarrier.await()).
  • Perform the write under writeMutex to ensure mutual exclusion.
  • Complete its own barrier, unblocking the next writer in the queue.

This guarantees that apply and commit operations are serialized and isolated, preventing overlapping writes and eliminating the observed race conditions.

Test Adjustments

Notes: No public API changes, behavior is limited to internal write sequencing and stability.

Closes #60

@harrytmthy harrytmthy added this to the 1.1.3 milestone Aug 24, 2025
@harrytmthy harrytmthy self-assigned this Aug 24, 2025
@harrytmthy harrytmthy added the bug Something isn't working label Aug 24, 2025
@harrytmthy harrytmthy merged commit cede53c into release/v1.1.3 Aug 24, 2025
3 checks passed
@harrytmthy harrytmthy deleted the fix/serialize-entry-writes branch August 24, 2025 16:57
harrytmthy added a commit that referenced this pull request Aug 24, 2025
* fix: Serialize entry writes (#61)

* release: v1.1.3 with serialized entry writes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant