From fe1f4a22ab332fe0817f4473cc7e967250a21a57 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Mon, 2 Nov 2026 10:34:58 +0100 Subject: [PATCH] TODO: FileLogPersistence shared tmp race Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WzxdWY1k4muZfdVJfb7YGJ --- ...ODO-fix-file-log-persistence-shared-tmp.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 crdt_sync_dart/TODO-fix-file-log-persistence-shared-tmp.md diff --git a/crdt_sync_dart/TODO-fix-file-log-persistence-shared-tmp.md b/crdt_sync_dart/TODO-fix-file-log-persistence-shared-tmp.md new file mode 100644 index 0000000..582d958 --- /dev/null +++ b/crdt_sync_dart/TODO-fix-file-log-persistence-shared-tmp.md @@ -0,0 +1,27 @@ +# Make FileLogPersistence.write safe under concurrent calls + +## what +`FileLogPersistence.write` (lib/src/io_store.dart) writes to a tmp file named +`..tmp` and renames it over the target. The name is per process, +not per call, so two overlapping writes in one process (per-keystroke upserts +in the todo app) share one tmp path: the first rename moves it away and the +second throws an unhandled `PathNotFoundException` on +`rename` of `todo_notes.json..tmp`. Seen in the todo app during +concurrent per-keystroke upserts. +Fix by serializing writes (a chained Future per instance, last write wins) +or by using a unique tmp name per call; keep the atomic rename. + +## done +A regression test in test/ fires 50 overlapping `write()` calls on one +instance, all complete without error, and the file then holds the text of a +call that was issued (not a torn mix). `dart test` in this package exits 0 +with coverage still 100%. + +## verify +`cd ~/src/utils/crdt_sync_dart && dart test --coverage=coverage`; then bump +the todo app's `crdt_sync` ref and run its full suite. + +## read first +- lib/src/io_store.dart + +REMOVE ME AFTER FINISH