Two concurrent gateway sessions calling memory add/replace/remove simultaneously could both read the old state, apply their changes independently, and write — the last writer silently drops the first writer's entry. Fix: wrap each mutation in a file lock (fcntl.flock on a .lock file). Under the lock, re-read entries from disk to get the latest state, apply the mutation, then write. This ensures concurrent writers serialize properly. The lock uses a separate .lock file since the memory file itself is atomically replaced via os.replace() (can't flock a replaced file). Readers remain lock-free since atomic rename ensures they always see a complete file.
22 KiB
22 KiB