fix(gateway): guard lock payload timestamps · openclaw/openclaw@98a1aa4
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -311,6 +311,32 @@ describe("gateway lock", () => {
|
311 | 311 | expect(lock).toBeNull(); |
312 | 312 | }); |
313 | 313 | |
| 314 | +it("falls back instead of throwing when lock payload clock is outside Date range", async () => { |
| 315 | +const env = await makeEnv(); |
| 316 | +const dateNowSpy = vi.spyOn(Date, "now").mockReturnValue(Date.parse("2026-05-30T12:00:00Z")); |
| 317 | +const lock = expectGatewayLock( |
| 318 | +await acquireGatewayLock({ |
| 319 | + env, |
| 320 | +allowInTests: true, |
| 321 | +timeoutMs: 30, |
| 322 | +pollIntervalMs: 2, |
| 323 | +now: () => 8_640_000_000_000_001, |
| 324 | +sleep: async () => {}, |
| 325 | +lockDir: resolveTestLockDir(), |
| 326 | +}), |
| 327 | +); |
| 328 | + |
| 329 | +try { |
| 330 | +const payload = JSON.parse(await fs.readFile(lock.lockPath, "utf8")) as { |
| 331 | +createdAt?: string; |
| 332 | +}; |
| 333 | +expect(payload.createdAt).toBe("2026-05-30T12:00:00.000Z"); |
| 334 | +} finally { |
| 335 | +dateNowSpy.mockRestore(); |
| 336 | +await lock.release(); |
| 337 | +} |
| 338 | +}); |
| 339 | + |
314 | 340 | it("wraps unexpected fs errors as GatewayLockError", async () => { |
315 | 341 | const env = await makeEnv(); |
316 | 342 | const openSpy = vi.spyOn(fs, "open").mockRejectedValueOnce( |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import net from "node:net";
|
6 | 6 | import path from "node:path"; |
7 | 7 | import { z } from "zod"; |
8 | 8 | import { resolveConfigPath, resolveGatewayLockDir, resolveStateDir } from "../config/paths.js"; |
| 9 | +import { resolveTimestampMsToIsoString } from "../shared/number-coercion.js"; |
9 | 10 | import { isPidAlive } from "../shared/pid-alive.js"; |
10 | 11 | import { safeParseJsonWithSchema } from "../utils/zod-parse.js"; |
11 | 12 | import { isGatewayArgv, parseProcCmdline, parseWindowsCmdline } from "./gateway-process-argv.js"; |
@@ -275,7 +276,7 @@ export async function acquireGatewayLock(
|
275 | 276 | const startTime = platform === "linux" ? readLinuxStartTime(process.pid) : null; |
276 | 277 | const payload: LockPayload = { |
277 | 278 | pid: process.pid, |
278 | | -createdAt: new Date(now()).toISOString(), |
| 279 | +createdAt: resolveTimestampMsToIsoString(now()), |
279 | 280 | configPath, |
280 | 281 | }; |
281 | 282 | if (typeof startTime === "number" && Number.isFinite(startTime)) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。