This directory contains the complete plan to fix the race condition in durable-queue's in-progress statistics by tracking in-progress items directly instead of computing them.
race-condition-analysis.md (5 min)issue12-quick-reference.md (3 min)issue12-implementation-plan.md (10 min)issue12-implementation-checklist.md (2-4 hours execution)immediate-stats reads three values non-atomically:
1. cnt = queue.size()
2. completed = completed.get()
3. enqueued = enqueued.get()
Then computes: in-progress = (enqueued - completed) - cnt
Between reads, other threads can:
- Remove items from queue (reduces cnt)
- Mark items as complete (increases completed)
Result: in-progress = (larger - larger) - smaller = NEGATIVE ✗
Track in-progress directly with an AtomicLong:
- Increment when take!() dequeues an item
- Decrement when mark-complete!() completes work
- Decrement when mark-retry!() requeues work
No race window. Always correct. ✓
| Location | Change | Lines |
|---|---|---|
initial-stats | Add :in-progress (AtomicLong. 0) | 407-410 |
immediate-stats | Read counter instead of computing | 412-419 |
mark-complete! | Decrement in-progress | 649-653 |
mark-retry! | Decrement in-progress | 643-647 |
take! | Increment in-progress | 668-695 |
docs/
├── race-condition-analysis.md ← Problem analysis
├── issue12-quick-reference.md ← One-page overview
├── issue12-implementation-plan.md ← Detailed guide
├── issue12-implementation-checklist.md ← Step-by-step checklist
└── ISSUE12_README.md ← This file
src/clj_commons/
└── durable_queue.clj ← 5 edits needed here
test/clj_commons/
└── durable_queue_test.clj ← Add tests here
✓ in-progress >= 0 (never negative) ✓ in-progress = items currently being processed ✓ All existing tests pass ✓ New tests verify race condition is fixed ✓ Stress tests with high concurrency are stable ✓ No performance degradation
race-condition-analysis.mdrace-condition-analysis.md Section 5Refer to the FAQ section in issue12-quick-reference.md
Last Updated: 2026-11-27 Status: Implementation Plan Complete, Ready for Execution Estimated Effort: 2-4 hours for experienced developer Risk Assessment: LOW
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |