Skip to content

Commit 721890d

Browse files
author
v9v
committed
Fix race condition in autosave
Fixes the case where multiple tmux sessions call auto-save at the same time, which occasionally results in multiple instances of save_all() running in parallel and causing issues like #3 and tmux-plugins/tmux-resurrect#294. The sequence in main() is: 1. Check enough_time_since_last_run_passed 2. Save 3. Update last_save_timestamp. The race here is: * process A finishes step 1 and is busy with step 2. The timestamp is not updated yet. * process B comes to step 1, sees the old timestamp and proceeds to step 2, too.
1 parent 90f4a00 commit 721890d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

scripts/continuum_save.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ fetch_and_run_tmux_resurrect_save_script() {
3535
}
3636

3737
main() {
38-
if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed; then
39-
fetch_and_run_tmux_resurrect_save_script
40-
fi
38+
(
39+
flock -n 101 || return # The code below is not thread-safe.
40+
if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed; then
41+
fetch_and_run_tmux_resurrect_save_script
42+
fi
43+
) 101>/tmp/tmux-continuum-autosave.lockfile
4144
}
4245
main

0 commit comments

Comments
 (0)