PrefectHQ
prefect
BlogDocsChangelog

Fix race condition in filesystem lease storage with atomic writes

#20153
Comparing
devin/1767968567-fix-flaky-concurrency-lease-test
(
dda3168
) with
main
(
9864bf2
)
CodSpeed Performance Gauge
0%
Untouched
2
Ignored
6

Benchmarks

Passed

bench_import_prefect_flow
benches/bench_import.py
CodSpeed Performance Gauge
0%
1.4 s1.4 s
bench_task_decorator
benches/bench_tasks.py
CodSpeed Performance Gauge
-1%
602.2 µs605.5 µs

Ignored

bench_flow_decorator
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
+4%
5.6 ms5.4 ms
bench_import_prefect
benches/bench_import.py
Ignored
CodSpeed Performance Gauge
0%
1.1 s1.1 s
bench_flow_call[options0]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-2%
166.9 ms170.2 ms
bench_task_submit
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
-7%
9.7 ms10.5 ms
bench_flow_call[options1]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
0%
107.7 ms107.4 ms
bench_task_call
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
+1%
34 ms33.5 ms

Commits

Click on a commit to change the comparison range
Base
main
9864bf2
-0.01%
Fix race condition in filesystem lease storage with atomic writes The race condition occurred because file writes were not atomic: - When writing lease files or the expiration index, readers could see partial/corrupted JSON data - The read_lease method would then delete the 'corrupted' file, destroying valid data This fix: 1. Adds _atomic_write_json() helper that uses write-to-temp-then-rename pattern to ensure readers never see partial content 2. Updates _save_expiration_index() to use atomic writes 3. Updates create_lease() to use atomic writes for lease files 4. Updates renew_lease() to use atomic writes 5. Removes destructive error handling in read_lease() - no longer deletes files on JSON decode errors since with atomic writes this should be rare and could be a transient issue Co-Authored-By: alex.s@prefect.io <ajstreed1@gmail.com>
18d1fc0
1 day ago
by devin-ai-integration[bot]
+0.4%
Restore cleanup behavior in read_lease (safe with atomic writes) With atomic writes in place, readers will never see partial/corrupted data from concurrent writes. So if a file IS corrupted, it's a real corruption issue that should be cleaned up, not a race condition. This restores the original cleanup behavior that the test expects. Co-Authored-By: alex.s@prefect.io <ajstreed1@gmail.com>
6cb1afc
1 day ago
by devin-ai-integration[bot]
-0.68%
Remove polling timeout logic from test file As requested in PR review - pytest-timeout already handles preventing tests from running indefinitely, so the custom polling timeout logic is unnecessary. Co-Authored-By: alex.s@prefect.io <ajstreed1@gmail.com>
dda3168
24 hours ago
by devin-ai-integration[bot]
© 2026 CodSpeed Technology
Home Terms Privacy Docs