避免清理失效锁时误删新锁
Project CI / AI game creator shell Rust shard 4/4 (push) Has been cancelled
Project CI / AI game creator shell Rust smoke (push) Has been cancelled
Project CI / AI game creator shell Rust crates (push) Has been cancelled
Project CI / Backend tests (push) Has been cancelled
Project CI / Native shell tests (push) Has been cancelled
Project CI / Frontend tests (push) Has been cancelled
Project CI / Repository checks (push) Has been cancelled
Project CI / AI game creator shell web tests (push) Has been cancelled
Project CI / AI game creator shell Rust shard 2/4 (push) Has been cancelled
Project CI / AI game creator shell Rust shard 1/4 (push) Has been cancelled
Project CI / AI game creator shell Rust shard 3/4 (push) Has been cancelled

使用原子重命名隔离失效锁文件
This commit is contained in:
2026-09-15 23:27:37 +08:00
parent 6d7b3e74a6
commit 34db1b6ad1
+5 -1
View File
@@ -502,8 +502,12 @@ function acquireBackupLock({ workDir, database }) {
) {
throw new Error(`已有数据库备份进程持有锁: ${lockPath} pid=${ownerPid}`);
}
const staleLockPath = `${lockPath}.stale-${process.pid}-${attempt}-${Date.now()}`;
try {
rmSync(lockPath);
// rename 是原子的:若另一个进程已先清理并重新建锁,这里只会得到 ENOENT,
// 不会把新进程的锁误删。
renameSync(lockPath, staleLockPath);
rmSync(staleLockPath, { force: true });
console.log(
`[database-backup] 已清理失效数据库备份锁,准备重新获取: ${lockPath} pid=${ownerPid || '<invalid>'}`,
);