Skip to content

Commit 4523738

Browse files
committed
fix(process-lock): drop dead Math.floor around mtime.getTime()
`Date.prototype.getTime()` already returns an integer millisecond count, so `Math.floor(stats.mtime.getTime())` was a no-op. Simplify the stale-check expression and update the comment to reflect that APFS's second-level filesystem precision just zeros the low bits — no extra flooring is needed.
1 parent 38e3b96 commit 4523738

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/process-lock.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ class ProcessLockManager {
227227
if (!stats) {
228228
return false
229229
}
230-
// Compare in milliseconds. APFS's mtime precision is second-level
231-
// but truncating the age to seconds was silently rounding sub-
232-
// second `staleMs` values up to ~1s (staleMs=500 → staleSeconds=0,
233-
// so the lock had to be 1s+ past mtime before it was considered
234-
// stale). Floor only the mtime side to absorb APFS quirks, keep
235-
// the threshold at full precision.
236-
const ageMs = Date.now() - Math.floor(stats.mtime.getTime())
237-
return ageMs > staleMs
230+
// Compare in milliseconds. The previous implementation floored
231+
// both sides to seconds, which silently rounded sub-second
232+
// `staleMs` values up to ~1s (staleMs=500 → staleSeconds=0, so
233+
// the lock had to be 1s+ past mtime before being considered
234+
// stale). Node returns mtime with ms precision on all platforms
235+
// we support; APFS's second-level filesystem precision just
236+
// means the low bits are zero, which the subtraction handles.
237+
return Date.now() - stats.mtime.getTime() > staleMs
238238
} catch {
239239
return false
240240
}

0 commit comments

Comments
 (0)