Skip to main content

Module lock

Module lock 

Source
Expand description

The cache lock file, kizz.lock in the cache directory.

A build holds an exclusive flock on the file for its whole run, through the locking of std::fs::File, so only one process uses a cache at a time.

  • The holder writes its LockDetails into the file.
  • A waiting process reports the holder’s details at once, and again whenever a different process takes the lock while it waits.
  • The kernel releases the lock when the holder exits for any reason, so a dead holder never blocks another process, and the next process takes over a file that a crash left behind.
  • After taking the lock, a process checks that the file it locked is still the file at the path, and retries if not. This closes the race between one process deleting the file and another locking it.
  • Releasing the lock, explicitly or by dropping the CacheLock, deletes the file while the lock is still held, so a normal exit, or an interrupted exit that unwinds to the release, leaves no file behind.
  • While the lock is held, its path is noted through kizz_threads::overflow, so that kizz’s handler of stack overflows deletes the file before kizz exits; the note is dropped before a release deletes the file.

The holder’s start time, which messages show in UTC, is converted with checked arithmetic, so no time read from another process’s file can make an operator overflow and panic (“Kizz never panics”).

Structs§

CacheLock
The exclusive lock on a cache, held until it is released or dropped.
LockDetails
What a lock holder writes into the lock file, so that a waiting process can say what it is waiting for.
LockOptions
How a process waits for the lock.

Enums§

LockError
Why the lock could not be taken or released.

Constants§

LOCK_FILE_NAME
The name of the lock file in the cache directory.