Skip to content

fix: treat null timestamp lock files as stale#233

Open
Jah-yee wants to merge 1 commit intojarrodwatts:mainfrom
Jah-yee:fix/0-byte-lock-file
Open

fix: treat null timestamp lock files as stale#233
Jah-yee wants to merge 1 commit intojarrodwatts:mainfrom
Jah-yee:fix/0-byte-lock-file

Conversation

@Jah-yee
Copy link

@Jah-yee Jah-yee commented Mar 18, 2026

Fixes #220 - 0-byte lock file permanently blocks usage display

When a lock file exists but is 0 bytes (created but not written to
due to process crash between fs.openSync and fs.writeFileSync),
readLockTimestamp returns null.

The stale-lock check was:
if (lockTimestamp != null && Date.now() - lockTimestamp > CACHE_LOCK_STALE_MS)

Since lockTimestamp IS null for 0-byte files, the condition is FALSE
and the stale check is skipped entirely. This causes the lock to be
treated as 'busy' forever, silently blocking usage display.

The fix treats null timestamp (corrupt/empty lock file) as stale,
matching the intent of the stale-lock mechanism.

Fixes jarrodwatts#220 - 0-byte lock file permanently blocks usage display

When a lock file exists but is 0 bytes (created but not written to
due to process crash between fs.openSync and fs.writeFileSync),
readLockTimestamp returns null.

The stale-lock check was:
  if (lockTimestamp != null && Date.now() - lockTimestamp > CACHE_LOCK_STALE_MS)

Since lockTimestamp IS null for 0-byte files, the condition is FALSE
and the stale check is skipped entirely. This causes the lock to be
treated as 'busy' forever, silently blocking usage display.

The fix treats null timestamp (corrupt/empty lock file) as stale,
matching the intent of the stale-lock mechanism.
@Jah-yee Jah-yee requested a review from jarrodwatts as a code owner March 18, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0-byte lock file permanently blocks usage display (silent failure)

1 participant