fix(server): parse pid start times in stable locale

This commit is contained in:
Mohamed Boudra
2026-07-09 15:42:47 +00:00
parent bc534ad09c
commit 215566bcb6
2 changed files with 3 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, test } from "vitest";
@@ -55,7 +55,6 @@ describe("pid-lock ownership", () => {
const replacementOwnerPid = process.pid + 10_000;
try {
await mkdir(paseoHome, { recursive: true });
await writeFile(
join(paseoHome, "paseo.pid"),
JSON.stringify({

View File

@@ -37,6 +37,7 @@ export class PidLockError extends Error {
const PROCESS_START_SKEW_TOLERANCE_MS = 60_000;
const PROCESS_LOCK_ACQUIRE_TOLERANCE_MS = 5 * 60_000;
const POSIX_PROCESS_TIME_ENV = { ...process.env, LC_ALL: "C", LANG: "C" };
let cachedClockTicksPerSecond: number | null = null;
function isPidRunning(pid: number): boolean {
@@ -96,6 +97,7 @@ function readPsProcessStartedAtMs(pid: number): number | null {
try {
const output = execFileSync("ps", ["-p", String(pid), "-o", "lstart="], {
encoding: "utf8",
env: POSIX_PROCESS_TIME_ENV,
timeout: 1000,
}).trim();
const parsed = Date.parse(output);