Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix race in disk cache #235

Merged
merged 2 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions boa/util/disk_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def caching_lookup(self, string, func):
return pickle.loads(f.read())
except OSError:
res = func()
tid = threading.get_ident()
tmp_p = p.with_suffix(f".{tid}.unfinished")
# use process ID and thread ID to avoid race conditions
job_id = f"{os.getpid()}.{threading.get_ident()}"
tmp_p = p.with_suffix(f".{job_id}.unfinished")
with tmp_p.open("wb") as f:
f.write(pickle.dumps(res))
# rename is atomic, don't really need to care about fsync
Expand Down
Loading