I removed every delete from my exactly‑once guard. Then the bugs moved.
Описание и применение
Удаление операций удаления из файловой системы, переход на генерации заявок и двойная проверка возраста заявок устранили дублирование платежей и гарантировали корректную обработку возвратов при высокой конкуренции.
Задача
Exactly‑once processing guard failed under concurrency and stale claim scenarios, causing duplicate charges and missed refunds.
Результат
Removed delete operations, switched to generation‑based claims, and added dual age checks, resulting in zero duplicate charges and reliable refunds under high concurrency.
Рабочий процесс
- 1. Workers attempt to create a claim file with os.open(..., O_CREAT|O_EXCL).
- 2. If claim exists, worker reads claim metadata and checks age using min(record_age, mtime_age).
- 3. If claim is stale, worker creates a new generation claim file without deleting the old one.
- 4. Workers process the charge only if they own the latest generation claim.
- 5. Refunds are processed after successful charge and logged; no duplicate refunds occur.
- 6. Tests validate concurrency, TTL handling, and clock drift scenarios.
Доказательства
fixed generation: 0/20 double executions 16 workers x 40 trials: 0 double executions
claim age. A claim records when it was made. That record is written by the claim, so it can be wrong
- Дата записи: 2026-09-08T19:00:27.375Z