Skip to content

fix: coordinate concurrent first downloads of the same cache key - #3

Merged
aaronkanzer merged 1 commit into
mainfrom
fix/coordinate-concurrent-first-cache-download
Aug 29, 2026
Merged

aaronkanzer merged 1 commit into
mainfrom
fix/coordinate-concurrent-first-cache-download

Conversation

@aaronkanzer

Copy link
Copy Markdown
Member

Summary

  • resolve()'s check-then-download wasn't coordinated across threads: N threads racing the first resolve() of a key (e.g. a thread pool calling chembl_bridge() right after enable_cache()) each saw it missing and each downloaded it in full. Reproduced directly: 16 threads calling chembl_bridge() concurrently on an empty cache logged 16 separate downloads of the same file instead of one.
  • Fixed with a per-key lock in cache.py: the first thread to reach a key downloads it, the rest wait and reuse the file it wrote.
  • Added a regression test asserting the download happens exactly once under concurrency, plus a README note.
  • Bumped to 0.2.4.

Test plan

  • pytest -q — 41 passed
  • mypy src/scigantic_bindingdb (strict) — clean
  • Reproduced the pre-fix redundant downloads (16/16 threads downloading) and confirmed exactly 1 download happens post-fix, both via the unit test and a live network repro

🤖 Generated with Claude Code

https://claude.ai/code/session_01L4ztUhMgoMFRicB8uiYx76

resolve()'s check-then-download wasn't coordinated across threads: N
threads racing the first resolve() of a key (e.g. a thread pool calling
chembl_bridge() concurrently right after enable_cache()) each saw it
missing and each downloaded it in full. Reproduced directly: 16 threads
calling chembl_bridge() concurrently on an empty cache logged 16 separate
"caching ..." downloads of the same file instead of one.

Fixed with a per-key lock: the first thread to reach a key downloads it,
the rest wait and then reuse the file it wrote. Verified the same repro
now logs exactly one download.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4ztUhMgoMFRicB8uiYx76
@aaronkanzer
aaronkanzer merged commit 3cf761c into main Aug 29, 2026
6 checks passed
@aaronkanzer
aaronkanzer deleted the fix/coordinate-concurrent-first-cache-download branch August 29, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant