fix(version): make the update write probe collision-free #140
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/YT-85-probe-filename-collision"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
check_writablebuilt its probe filename from the pid plusSystemTime::now()nanos, so uniqueness depended on the clock ticking between calls. Undercargo testeveryrun(...)test incommands::version::update::testsshares one pid and one parent directory and the libtest harness runs them on concurrent threads, so two threads reading the same clock tick produced the same probe name; the loser of thecreate_newrace gotEEXISTand the catch-all arm reportedprobe write access for <dir>: File exists (os error 17)for a directory that is in fact writable. The victim test was arbitrary, which is why the CI failure moved between runs.probe_filenamenow appends a process-wide relaxed atomic counter, so two calls can never return the same string regardless of clock resolution; the pid still separates live processes and the nanos component still separates a recycled pid from a stale probe left by a killed process.check_writableadditionally retries with a fresh name onErrorKind::AlreadyExists, bounded at 3 attempts, for that residual stale-probe case; thePermissionDeniedfriendly message and theprobe write access for <dir>context for every other error kind are unchanged, soNotFoundis still reported immediately.Tests: a new
check_writable_is_safe_from_concurrent_callersruns 16 threads through 200 barrier-synchronised rounds against one sharedtempfile::tempdir()and asserts every probe returnedOk(it reports 13-35File existsfailures against the pre-fix code).probe_filename_unique_per_callnow asserts uniqueness across 1000 calls instead of two, so it no longer depends on the clock ticking. No test is serialised, ignored, or moved to a single-threaded runner.#YT-85