Fix dangling DBMS_LOCK hash table built in a per-query context - #1607
Fix dangling DBMS_LOCK hash table built in a per-query context#1607Aias00 wants to merge 2 commits into
Conversation
dbms_lock_init_hash_table() created the hash table without HASH_CONTEXT, so it was allocated in CurrentMemoryContext on the first SQL call and freed when that query ended, leaving the static pointer dangling and the next DBMS_LOCK call reading freed memory. Build it in TopMemoryContext like dbms_session does. Closes IvorySQL#1604
|
Warning Review limit reached
Next review available in: 10 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe DBMS_LOCK hash table now uses ChangesDBMS_LOCK hash-table initialization
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to This localized change keeps the DBMS_LOCK hash table alive across queries and prevents subsequent calls from accessing freed memory; no actionable merge-blocking risk remains after normal checks and review. 🚥 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 |
Like dbms_output and dbms_session, drop the session-local lock hash table when DISCARD ALL/PACKAGES runs, so stale lock records do not survive a session reset.
Summary
Fixes #1604:
dbms_lock_init_hash_table()calledhash_create()withoutHASH_CONTEXT, so the table was allocated inCurrentMemoryContext. Since the table is lazily initialized from SQL functions, that context is a per-query executor context; when the query ended the table was freed while the staticdbms_lock_hash_tablepointer kept referencing it. The nextDBMS_LOCK.REQUEST/RELEASEthen ranhash_search()on freed memory.The fix passes
ctl.hcxt = TopMemoryContextwithHASH_CONTEXT(same approach asdbms_session_init()), and adds the missingutils/memutils.hinclude forTopMemoryContext.Test plan
make -C contrib/ivorysql_ora src/builtin_packages/dbms_lock/dbms_lock.ocompiles cleanly.CALL dbms_lock.request(...)followed by a secondDBMS_LOCKcall in the same backend no longer touches freed memory.Summary by CodeRabbit