fix(auth): fail closed on unreadable stale locks · openclaw/openclaw@f84d031
steipete
·
2026-05-14
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -69,9 +69,10 @@ describe("acquireFileLock", () => {
|
69 | 69 | stale: 10, |
70 | 70 | } as const; |
71 | 71 | |
| 72 | +const deadPid = Number.MAX_SAFE_INTEGER; |
72 | 73 | await fs.writeFile( |
73 | 74 | lockPath, |
74 | | -JSON.stringify({ pid: 999_999, createdAt: new Date(Date.now() - 60_000).toISOString() }), |
| 75 | +JSON.stringify({ pid: deadPid, createdAt: new Date(Date.now() - 60_000).toISOString() }), |
75 | 76 | "utf8", |
76 | 77 | ); |
77 | 78 | |
@@ -84,6 +85,38 @@ describe("acquireFileLock", () => {
|
84 | 85 | } |
85 | 86 | }); |
86 | 87 | |
| 88 | +it("keeps a reported stale lock when its payload is not readable", async () => { |
| 89 | +const filePath = path.join(tempDir, "payload-pending"); |
| 90 | +const lockPath = `${filePath}.lock`; |
| 91 | +const options = { |
| 92 | +retries: { |
| 93 | +retries: 0, |
| 94 | +factor: 1, |
| 95 | +minTimeout: 1, |
| 96 | +maxTimeout: 1, |
| 97 | +}, |
| 98 | +stale: 10, |
| 99 | +} as const; |
| 100 | + |
| 101 | +await fs.writeFile(lockPath, "{", "utf8"); |
| 102 | + |
| 103 | +let caught: { lockPath?: string } | undefined; |
| 104 | +await expect( |
| 105 | +(async () => { |
| 106 | +try { |
| 107 | +await acquireFileLock(filePath, options); |
| 108 | +} catch (err) { |
| 109 | +caught = err as { lockPath?: string }; |
| 110 | +throw err; |
| 111 | +} |
| 112 | +})(), |
| 113 | +).rejects.toMatchObject({ |
| 114 | +code: FILE_LOCK_TIMEOUT_ERROR_CODE, |
| 115 | +}); |
| 116 | +await expect(fs.realpath(caught?.lockPath ?? "")).resolves.toBe(await fs.realpath(lockPath)); |
| 117 | +await expect(fs.readFile(lockPath, "utf8")).resolves.toBe("{"); |
| 118 | +}); |
| 119 | + |
87 | 120 | it("keeps a reported stale lock when its owner pid is alive", async () => { |
88 | 121 | const filePath = path.join(tempDir, "live-owner"); |
89 | 122 | const lockPath = `${filePath}.lock`; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。