diff options
Diffstat (limited to 'scripts/chat.py')
| -rwxr-xr-x | scripts/chat.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/scripts/chat.py b/scripts/chat.py index e19fb6b..5b44b64 100755 --- a/scripts/chat.py +++ b/scripts/chat.py @@ -78,9 +78,11 @@ def reply(thread, text): with open(tmp, 'w') as fh: json.dump(msgs, fh, ensure_ascii=False) os.chmod(tmp, 0o664) + # replace INSIDE the lock: doing it after unlock lets a second writer read + # the pre-replace snapshot and rename over this message (lost update). + os.replace(tmp, path) finally: fcntl.flock(lock, fcntl.LOCK_UN) - os.replace(tmp, path) # atomic: a poll never sees a half-written file return msg |