Skip to content

🐛 fix(soft-rw): renew waiters and bound cleanup - #1097

Merged
gaborbernat merged 4 commits into
tox-dev:mainfrom
gaborbernat:review/soft-rw-protocol-e
Nov 20, 2026
Merged

gaborbernat merged 4 commits into
tox-dev:mainfrom
gaborbernat:review/soft-rw-protocol-e

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

A SoftReadWriteLock waiter that resumes after its lease expires now withdraws its old token before requesting a new one. A delayed cleanup can then remove the old record while the new hold remains valid. The waiter counts time spent asleep on macOS and systems with CLOCK_BOOTTIME. Elsewhere it uses the host's monotonic clock. Fixes #1010 and fixes #1052.

Each sweep lists up to 65,537 names per directory and sorts the candidates. It reads up to 256 orphan holder records and 256 temporary commit files, continuing from its last position. To track changes between sweeps, the lock keeps one fixed-size digest per observed name. Fixes #995 and fixes #997.

A generation directory with more than 65,536 entries raises a protocol error. If the directory crosses the limit after a writer publishes a generation, the writer declines the commit and leaves the record in place because a peer may already have extended it.

A delayed sweep could remove a waiter's record after it resumed and gained
the lock. With no recorded lease, a peer with a shorter threshold could
enter alongside the holder.

Retire a token when its record or commit spans the stale threshold, so a
late unlink reaches only the old record name.

Fixes tox-dev#1010
Another host can mark a waiter's token stale during host suspension while
the waiter sees less than one lease on CLOCK_MONOTONIC. A delayed sweep can
then unlink a newly granted holder's record.

Count suspended time for the local token's lease age on systems with
CLOCK_BOOTTIME. Peer observations keep their monotonic clock, since a host
cannot assume that a filesystem read stayed current while it slept.

Fixes tox-dev#1052
@gaborbernat
gaborbernat force-pushed the review/soft-rw-protocol-e branch from da53c10 to 09ae8ea Compare November 20, 2026 15:35
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 17:43
@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 17:52
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 17:55
@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 19:45
A user able to populate a non-sticky shared lock tree could make one
acquire sweep read every planted holder and commit record before the
caller's deadline was checked.

Limit orphan cleanup and generation pruning per pass. Reject a partial
generation listing because it may omit the current head; later passes
can clean the remaining orphan records.

Refs tox-dev#995
@gaborbernat
gaborbernat force-pushed the review/soft-rw-protocol-e branch from 09ae8ea to 4b463f8 Compare November 20, 2026 19:46
@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 21:59
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 22:00
@gaborbernat
gaborbernat merged commit 03b89d1 into tox-dev:main Nov 20, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant