fix: harden Matrix snapshot lock timing

This commit is contained in:
Gustavo Madeira Santana
2026-04-02 19:58:58 -04:00
parent 9c5d2613f1
commit 392e411ffd
2 changed files with 7 additions and 2 deletions

View File

@@ -1194,7 +1194,9 @@ describe("MatrixClient crypto bootstrapping", () => {
const callsAfterStart = databasesSpy.mock.calls.length;
await vi.advanceTimersByTimeAsync(60_000);
expect(databasesSpy.mock.calls.length).toBeGreaterThan(callsAfterStart);
await vi.waitFor(() => {
expect(databasesSpy.mock.calls.length).toBeGreaterThan(callsAfterStart);
});
client.stop();
const callsAfterStop = databasesSpy.mock.calls.length;

View File

@@ -8,6 +8,9 @@ import { LogService } from "./logger.js";
// Advisory lock options for IDB snapshot file access. Without locking, the
// gateway's periodic 60-second persist cycle and CLI crypto commands (e.g.
// `openclaw matrix verify bootstrap`) can corrupt each other's state.
// Use a longer stale window than the generic 30s default because snapshot
// restore and large crypto-store dumps can legitimately hold the lock for
// longer, and reclaiming a live lock would reintroduce concurrent corruption.
const IDB_SNAPSHOT_LOCK_OPTIONS: FileLockOptions = {
retries: {
retries: 10,
@@ -16,7 +19,7 @@ const IDB_SNAPSHOT_LOCK_OPTIONS: FileLockOptions = {
maxTimeout: 5_000,
randomize: true,
},
stale: 30_000,
stale: 5 * 60_000,
};
type IdbStoreSnapshot = {