fix(dpmodel): release merged LMDB cache references#5797
Conversation
Balance each source environment acquired by merge_lmdb through the refcount-aware cache close path, including exceptions. Add a regression proving merge preserves shared readers and leaves the cache reference count unchanged. Coding-Agent: Codex Codex-Version: codex-cli 0.144.1 Model: gpt-5.6-sol Reasoning-Effort: xhigh
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesLMDB cache lifecycle
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5797 +/- ##
==========================================
- Coverage 79.85% 78.31% -1.54%
==========================================
Files 1022 1049 +27
Lines 117351 120651 +3300
Branches 4313 4351 +38
==========================================
+ Hits 93706 94490 +784
- Misses 22101 24598 +2497
- Partials 1544 1563 +19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Release the retained readers with del so finalizers run without assignments that CodeQL flags as unused. Coding-Agent: Codex Codex-Version: codex-cli 0.144.4 Model: gpt-5.6-sol Reasoning-Effort: xhigh
Summary
merge_lmdb()through the refcount-aware LMDB cache pathfinallyso malformed metadata or copy failures also balance the merge's temporary referenceRoot cause and fix
_open_lmdb()caches readonly environments by resolved path because python-lmdb does not permit independently opening the same path multiple times in one process. Every acquisition increments a cache refcount, and_close_lmdb()is the matching release operation.merge_lmdb()acquired each source through_open_lmdb(), but calledsrc_env.close()directly. If a reader already shared that cached environment, the merge invalidated its live handle while the cache still retained it. A later reader could then receive the same closed object.The source loop now pairs
_open_lmdb(src_path)with_close_lmdb(src_path)infinally. This releases only the reference owned by the merge; existing readers retain their references and environment. Thefinallyscope covers metadata parsing, source/destination transactions, frame copying, and system-ID offset updates.Why existing tests missed this
Existing merge tests opened readers only after the merge and did not keep a source reader alive across the operation. They therefore never exercised the cache-sharing condition that makes a direct
Environment.close()unsafe.The new regression:
LmdbDataReaderand records its cached environment/refcount;On the previous implementation, the existing reader fails deterministically with:
lmdb.Error: Attempt to operate on closed/deleted/dropped object.Validation performed:
TestMergeLmdbSystemIdsgroup: 4 passedruff format --check .ruff check .git diff --checkCloses #5635.
Coding agent: Codex
Codex version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
Bug Fixes
Tests