Skip to content

🐛 fix(soft): keep marker creation tied to its file - #1049

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/soft-interrupted-create-04b
Nov 21, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/soft-interrupted-create-04b

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

An interrupted soft lock acquisition could leave an empty marker that blocked the next caller. An existing Windows symlink could also direct the holder record to a different file. Both problems affected SoftFileLock, MarkerSoftFileLock, and SoftFileLease.

The acquiring process records the descriptor as it creates the marker, including the private replacement it prepares when taking over a stale lock. If acquisition raises before it returns, cleanup can identify the file it created. On Windows, exclusive native creation treats an existing symlink as an occupied name and leaves its target untouched.

A Windows marker remains readable while held. If descriptor conversion fails, cleanup writes a newline and requests deletion through a handle to that marker. If a reader temporarily denies deletion, a later caller can reclaim the malformed marker. An uncatchable exit or a filesystem that refuses both the write and deletion can still leave an empty marker.

flowchart TD
    Start["Create marker"] --> Exists{"Name occupied?"}
    Exists -->|Yes| Wait["Handle contention"]
    Exists -->|No| FD["Record descriptor"]
    FD --> Ready{"Record written?"}
    Ready -->|Yes| Hold["Report acquired"]
    Ready -->|No| Clean["Close descriptor and clean up marker"]
    classDef path fill:#cfe4ff,stroke:#1f6feb,color:#0b1f3a
    classDef outcome fill:#cbe8d3,stroke:#287544,color:#102519
    class Start,Exists,FD,Ready path
    class Wait,Hold,Clean outcome
Loading

Supersedes #1055.

Fixes #996. Fixes #1009.

Reported by OSS Scanner (ANT-2026-04B5BJXO and ANT-2026-75X3BYMX).

@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 15:32
@gaborbernat gaborbernat changed the title 🐛 fix(soft): clean interrupted marker create 🐛 fix(soft): keep marker creation tied to its file Nov 20, 2026
@gaborbernat
gaborbernat changed the base branch from main to fix/soft-release-identity-jvg November 20, 2026 15:47
@gaborbernat
gaborbernat force-pushed the fix/soft-interrupted-create-04b branch from d9dd041 to d7723d5 Compare November 20, 2026 15:47
gaborbernat added a commit to gaborbernat/filelock that referenced this pull request Nov 20, 2026
Base Windows strict claims on the private-record policy from tox-dev#1045 and
the marker API from tox-dev#1049.
@gaborbernat
gaborbernat force-pushed the fix/soft-interrupted-create-04b branch from d7723d5 to 066ffc7 Compare November 20, 2026 15:57
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 17:36
@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 19:33
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 21:45
@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 22:00
@gaborbernat
gaborbernat deleted the branch tox-dev:fix/soft-release-identity-jvg November 20, 2026 23:56
@gaborbernat gaborbernat reopened this Nov 20, 2026
@gaborbernat
gaborbernat changed the base branch from fix/soft-release-identity-jvg to main November 20, 2026 23:58
Capture the descriptor while creating the marker so an interrupted acquire
can close it and identify its file. On Windows, create the marker without
following a final symlink. If descriptor conversion fails, request deletion
through a handle to the marker this call created.

Fixes tox-dev#996
Fixes tox-dev#1009
@gaborbernat
gaborbernat force-pushed the fix/soft-interrupted-create-04b branch from 5205cc4 to 3b17f00 Compare November 21, 2026 00:00
@gaborbernat
gaborbernat marked this pull request as ready for review November 21, 2026 00:22
@gaborbernat
gaborbernat merged commit e6e4d05 into tox-dev:main Nov 21, 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

Development

Successfully merging this pull request may close these issues.

SoftFileLock creates dangling symlink targets on Windows Interrupted SoftFileLock creation leaves a permanent empty marker

1 participant