mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 13:31:25 +00:00
refactor(agents): dedupe session write lock release
This commit is contained in:
@@ -162,24 +162,25 @@ export async function acquireSessionWriteLock(params: {
|
|||||||
}
|
}
|
||||||
const normalizedSessionFile = path.join(normalizedDir, path.basename(sessionFile));
|
const normalizedSessionFile = path.join(normalizedDir, path.basename(sessionFile));
|
||||||
const lockPath = `${normalizedSessionFile}.lock`;
|
const lockPath = `${normalizedSessionFile}.lock`;
|
||||||
|
const release = async () => {
|
||||||
|
const current = HELD_LOCKS.get(normalizedSessionFile);
|
||||||
|
if (!current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
current.count -= 1;
|
||||||
|
if (current.count > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HELD_LOCKS.delete(normalizedSessionFile);
|
||||||
|
await current.handle.close();
|
||||||
|
await fs.rm(current.lockPath, { force: true });
|
||||||
|
};
|
||||||
|
|
||||||
const held = HELD_LOCKS.get(normalizedSessionFile);
|
const held = HELD_LOCKS.get(normalizedSessionFile);
|
||||||
if (held) {
|
if (held) {
|
||||||
held.count += 1;
|
held.count += 1;
|
||||||
return {
|
return {
|
||||||
release: async () => {
|
release,
|
||||||
const current = HELD_LOCKS.get(normalizedSessionFile);
|
|
||||||
if (!current) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
current.count -= 1;
|
|
||||||
if (current.count > 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
HELD_LOCKS.delete(normalizedSessionFile);
|
|
||||||
await current.handle.close();
|
|
||||||
await fs.rm(current.lockPath, { force: true });
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,19 +196,7 @@ export async function acquireSessionWriteLock(params: {
|
|||||||
);
|
);
|
||||||
HELD_LOCKS.set(normalizedSessionFile, { count: 1, handle, lockPath });
|
HELD_LOCKS.set(normalizedSessionFile, { count: 1, handle, lockPath });
|
||||||
return {
|
return {
|
||||||
release: async () => {
|
release,
|
||||||
const current = HELD_LOCKS.get(normalizedSessionFile);
|
|
||||||
if (!current) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
current.count -= 1;
|
|
||||||
if (current.count > 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
HELD_LOCKS.delete(normalizedSessionFile);
|
|
||||||
await current.handle.close();
|
|
||||||
await fs.rm(current.lockPath, { force: true });
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const code = (err as { code?: unknown }).code;
|
const code = (err as { code?: unknown }).code;
|
||||||
|
|||||||
Reference in New Issue
Block a user