fix(common): lock registry prevents EXIT trap overwrite orphaning locks
Scripts calling acquire_lock followed by acquire_rsync_lock (rsync.sh) or a custom EXIT trap (resource_watchdog.sh) would overwrite the lock release trap, leaving the first lock file behind on exit. Replace per-acquire trap with a _LOCK_FILES registry. _register_lock() appends each lock file to the array and sets a single _release_all_locks trap. All acquired locks release together on exit regardless of how many traps are subsequently set or overwritten. resource_watchdog.sh: chain _release_all_locks into both its custom trap and the state-persisted disarm path so the lock releases in all exit paths.
This commit is contained in:
@@ -151,7 +151,7 @@ _rw_trap_restart_stopped() {
|
||||
fi
|
||||
done
|
||||
}
|
||||
trap _rw_trap_restart_stopped EXIT
|
||||
trap "_release_all_locks; _rw_trap_restart_stopped" EXIT
|
||||
|
||||
# ==============================================================================================
|
||||
# ━━━ State Helpers ━━━
|
||||
@@ -580,6 +580,6 @@ fi
|
||||
# ==============================================================================================
|
||||
rm_state_set "rm_paused_containers" "$PAUSED_LIST"
|
||||
rm_state_set "rm_stopped_containers" "$STOPPED_LIST"
|
||||
trap - EXIT # state persisted — stopped containers recorded, trap no longer needed
|
||||
trap "_release_all_locks" EXIT # state persisted — disable restart trap, keep lock cleanup
|
||||
# Touch state file each run so docker_watchdog stale guard sees fresh mtime
|
||||
touch "$RW_STATE_FILE" 2>/dev/null
|
||||
|
||||
Reference in New Issue
Block a user