Skip to content

🐛 fix(lock): validate holds before reuse - #1098

Merged
gaborbernat merged 10 commits into
mainfrom
reimplement/a2
Nov 20, 2026
Merged

gaborbernat merged 10 commits into
mainfrom
reimplement/a2

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

A nested acquire could report success after a Unix unlock raised or a lease heartbeat detected a lost claim. Sync and async acquires now raise RuntimeError before increasing the depth of either hold. Retry an uncertain Unix unlock with release(). Release a lost lease before acquiring it again.

A singleton shared through relative and absolute paths raises RuntimeError if a directory change sends its original path to another file. Construct a new lock with the absolute path to acquire the intended file. Reading the current marker's owner still works.

During interpreter shutdown, a worker's forced release leaves the main thread's hold available to its exit callbacks.

The November 2026 filelock review reported ANT-2026-IWDBI4I2, ANT-2026-2NN0JREM, ANT-2026-BS2V9OOX, and ANT-2026-5UMFVO63.

Fixes #999, fixes #998, fixes #1018, fixes #1008.

A callback can interrupt the acquire after the backend takes the lock.
Restore the previous depth on failure and refuse a release that would
consume the level still being acquired.

Fixes #1030
Fixes #1071
Fixes #1076
An interrupted release can resume after another thread has acquired the
lock at the same depth. Check the acquisition generation under the
transition gate before retrying.

Fixes #1004
A signal handler can acquire a peer after the initial deadlock check.
Check the pinned path again before waiting on that peer.

Fixes #1083
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 18:15
@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 19:32
An errno-bearing signal handler can run after flock released the kernel
lock and before filelock clears its descriptor. The instance then treats
a later acquire as reentrant and enters without exclusion.

Mark the transition uncertain before flock. Require an explicit release
retry before the instance can acquire again; a genuine failed syscall
keeps its descriptor for that retry.

Fixes #999
After a lease reports a lost claim, its descriptor stays open while existing
users finish. New calls on the same instance must not join it because a peer
may already own the marker.

Check reentry before increasing the hold count. Match the compromise token to
the current claim so a delayed report for an earlier claim does not reject a
new one.

Fixes #998
A singleton built from a relative path can be reused for an absolute
path. After chdir, acquisition followed the relative spelling and
could report a hold on a different file.

Reject that acquisition once the shared paths diverge. A new lock
constructed after chdir can still use the requested absolute path.

Fixes #1018
Threading marks the main thread done before atexit callbacks run. A
forced release from another thread could close a hold that the main
thread still needs. Keep it until the main thread stops executing.

Fixes #1008
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 21:36
@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 22:00
Base automatically changed from fix/ynl-counter-signal-agent to main November 20, 2026 22:01
Main contains the squashed acquisition changes from #1060. Use its
original head as the common base to keep the five hold-validation commits
from #1098.
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 22:37
@gaborbernat
gaborbernat merged commit 27084ed into main Nov 20, 2026
49 checks passed
@gaborbernat
gaborbernat deleted the reimplement/a2 branch November 20, 2026 23:56
@gaborbernat
gaborbernat restored the reimplement/a2 branch November 20, 2026 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant