fix: reuse the DuckDB connection across calls, fix a cache download race - #1
Merged
Merged
Conversation
connect() opened a brand new duckdb.connect() on every call, including from inside measurements(), chembl_bridge(), dti_pairs() and query(), re-running INSTALL/LOAD httpfs, re-creating the S3 secret, and re-registering all five core views every time. Measured: 8 repeat calls to measurements() went from 318s (39.8s/call) to 5.3s (0.66s/call, ~60x) after switching to a cursor() on a shared, lazily-created base connection per release, the same fix already shipped in scigantic-pubchem's bridge.py for the same reason. cache.py's atomic download used a temp filename derived only from the cache key, so two threads racing to fill the same key raced each other's os.replace() too; reproduced directly, 11/16 threads failed with FileNotFoundError in every trial. Fixed with a uuid-suffixed temp name per call, mirroring scigantic-pubchem's cache.py fix for the identical bug. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L4ztUhMgoMFRicB8uiYx76
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
connect()opened a brand newduckdb.connect()on every call frommeasurements(),chembl_bridge(),dti_pairs()andquery(), re-runningINSTALL/LOAD httpfs, re-creating the S3 secret, and re-registering all five core views every time. Now reuses a lazily-created, per-release base connection and hands out acursor()per call (thread-safe, verified). Measured: 8 repeat calls tomeasurements()went from 318s (39.8s/call) to 5.3s (0.66s/call), ~60x. Same fix already shipped inscigantic-pubchem'sbridge.py.cache.py's atomic download used a temp filename derived only from the cache key, so two threads racing to fill the same key raced each other'sos.replace()too. Reproduced directly: 11/16 threads failed withFileNotFoundErrorin every trial before the fix. Fixed with a uuid-suffixed temp name per call, mirroringscigantic-pubchem's cache.py fix for the identical bug.Test plan
pytest -q— 38 passedmypy src/scigantic_bindingdb(strict) — clean🤖 Generated with Claude Code
https://claude.ai/code/session_01L4ztUhMgoMFRicB8uiYx76