pypi / filelock
filelock
What changed in filelock 3 to 4, from its official release notes, upgrade guides and advisories. Sources checked 2026-12-04.
9 breaking20 security1 tooling15 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initfilelock 443 changes
Breaking changes 9
UnixFileLock now refuses with PermissionError a lock file owned by another account under a sticky parent, preventing two processes from holding locks at the same path. Files owned by the directory owner are still accepted.
If a lock transition another thread never finishes blocks a fork, the child exits with status 70 after 30 seconds and the parent continues.
On runtimes without dir_fd other than Windows, it refuses a protocol directory owned by another account under a sticky parent.
Contended FileLock and SoftFileLock acquisitions now raise Timeout when elapsed time reaches the requested timeout, avoiding indefinite retries at the deadline.
ReadWriteLock, SoftReadWriteLock and their async wrappers now raise TypeError when blocking is not a bool, in the constructor and on acquire.
A non-bool blocking argument now raises TypeError instead of being treated as truthy, which could make a single-attempt call wait for the timeout.
Resolving the name now raises ImportError when a missing module other than sqlite3 prevents loading it; the name is None only when SQLite is unavailable.
Resolving the name now raises ImportError when a missing module other than sqlite3 prevents loading it; the name is None only when SQLite is unavailable.
A forked child of a process holding a lease now starts with an unheld claim instead of inheriting the parent's token, compromise, and heartbeat.
Security 18
filelock: On Windows an oplock on a soft lock's marker holds SoftFileLock.acquire() past its timeout and blocks the stale break
filelock ReadWriteLock: a crafted lock database makes every acquire stall or hang regardless of timeout
filelock: ReadWriteLock on the hard-link route deletes any directory another user renames onto its .filelock-* link directory name
filelock: ReadWriteLock on Windows acts on SQLite side files another local user places beside its database
filelock ReadWriteLock: SQLite reopens the lock database by name, so a planted symlink or journal file makes the lock user's process overwrite or unlink its own files
filelock: SoftFileLock evicts a fresh lock file whose watched age another local user's pre-dated file passed on through inode reuse
filelock: SoftFileLock removes a live holder's marker when another user forges the PID in a writable marker
filelock: SoftFileLock stale-break restore follows a swapped-in symbolic link and hard-links a file of the user running the lock into the lock directory
filelock: SoftFileLock stale-lock break removes a live lock file on a reused inode number and admits two holders
filelock: SoftReadWriteLock follows a lock tree swapped in after its first acquire and writes lock records into directories of the user running the lock
filelock: SoftReadWriteLock holder refresh writes through a hard link and hangs on a named pipe that another local user renames over its record
filelock: StrictSoftFileLock and SoftReadWriteLock adopt a protocol directory another user created first, losing mutual exclusion
filelock: StrictSoftFileLock creates its claim directories without the lock mode, so another local user with a write bit on them can end a live hold
filelock: StrictSoftFileLock follows a symbolic link swapped in at <path>.filelock and creates claim files in a directory another local user chooses
filelock: Symlink swap during SoftFileLock's writability check leaks whether a path exists and is writable by the lock taker
filelock: UnixFileLock truncates and chmods any regular file another user renames or hard-links onto the lock path
filelock: WindowsFileLock ignores mode: a 0o600 lock file and the ReadWriteLock database inherit the directory ACL
filelock: ReadWriteLock follows a symlink at the lock path into SQLite
Tooling 1
Every wheel now includes a PEP 770 CycloneDX SBOM in its
.dist-info/sbomsdirectory, written at build time by python-sbom.
Fixes and other changes 15
With a poll_interval below 0.05 seconds, contended retries use a jittered, widening window instead of a fixed interval.
Locks still referenced at interpreter exit are released before module teardown, with exceptions for running daemon-thread holds and thread_local=False locks while another thread runs.
On Windows, paths differing only in drive-letter or UNC-share case share a singleton and trigger same-thread deadlock detection.
Dropping a lock during interpreter shutdown, including read-write locks, no longer prints an ignored exception at exit.
Garbage collection on its own heartbeat thread no longer deadlocks that thread and leaves later os.fork() calls waiting forever.
Releasing a soft lock whose marker was replaced by a peer no longer raises AttributeError on GraalPy.
Reclaims a dead holder's lease marker despite a different lease duration, preventing the lock from staying wedged; a live holder with a different duration still raises LeaseSettingsMismatch.
Fixes a race affecting SoftFileLock, MarkerSoftFileLock and SoftFileLease when three or more contenders reclaim a dead marker, preventing a live holder's marker from being stranded or a second holder from being admitted.
Nested acquisition of a held
FileLockorSoftFileLockno longer recreates the lock file's parent directory after it has been renamed.A read-only reopen now uses the path pinned during acquisition, avoiding resolution against a changed working directory after a refused read-write open.
Acquisition now works in group-writable directories with inherited ACLs by restricting the link directory's write access to its owner, including on filesystems that refuse to close it.
The protocol tree now handles EMLINK from a no-follow open that refuses a symlink, so heartbeat reports lost ownership rather than a transient refresh error.
If the first read of a new marker's identity fails, the lock reads it again before rollback, preventing an empty marker from blocking later acquisitions on Windows.
Stranded restore claims with out-of-range process numbers or non-ASCII digits are ignored, preventing overflow errors and locks that cannot reclaim dead holders.
On Windows, a soft lock no longer waits forever by retaining a marker for an exited holder when another process still holds a handle to it.
filelock 32 changes
Security 2
filelock Time-of-Check-Time-of-Use (TOCTOU) Symlink Vulnerability in SoftFileLock
filelock has a TOCTOU race condition which allows symlink attacks during lock file creation