Skip to content

Fix dangling DBMS_LOCK hash table built in a per-query context - #1607

Open
Aias00 wants to merge 2 commits into
IvorySQL:masterfrom
Aias00:fix/dbms-lock-hash-context-1604
Open

Fix dangling DBMS_LOCK hash table built in a per-query context#1607
Aias00 wants to merge 2 commits into
IvorySQL:masterfrom
Aias00:fix/dbms-lock-hash-context-1604

Conversation

@Aias00

@Aias00 Aias00 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1604: dbms_lock_init_hash_table() called hash_create() without HASH_CONTEXT, so the table was allocated in CurrentMemoryContext. 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 static dbms_lock_hash_table pointer kept referencing it. The next DBMS_LOCK.REQUEST/RELEASE then ran hash_search() on freed memory.

The fix passes ctl.hcxt = TopMemoryContext with HASH_CONTEXT (same approach as dbms_session_init()), and adds the missing utils/memutils.h include for TopMemoryContext.

Test plan

  • make -C contrib/ivorysql_ora src/builtin_packages/dbms_lock/dbms_lock.o compiles cleanly.
  • Manual repro: first CALL dbms_lock.request(...) followed by a second DBMS_LOCK call in the same backend no longer touches freed memory.

Summary by CodeRabbit

  • Bug Fixes
    • Improved DBMS_LOCK hash table memory handling for greater runtime stability.

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
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Aias00, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d976af8-ca6f-481e-9173-96619afcdc5d

📥 Commits

Reviewing files that changed from the base of the PR and between b281636 and cc04630.

📒 Files selected for processing (3)
  • contrib/ivorysql_ora/src/builtin_packages/dbms_lock/dbms_lock.c
  • contrib/ivorysql_ora/src/include/ivorysql_ora.h
  • contrib/ivorysql_ora/src/ivorysql_ora.c

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e03a6d2-4fd1-4bb9-9dcf-501d646b9236

📥 Commits

Reviewing files that changed from the base of the PR and between c3529ba and b281636.

📒 Files selected for processing (1)
  • contrib/ivorysql_ora/src/builtin_packages/dbms_lock/dbms_lock.c

📝 Walkthrough

Walkthrough

The DBMS_LOCK hash table now uses TopMemoryContext and HASH_CONTEXT during creation. The change adds the required memory-context header.

Changes

DBMS_LOCK hash-table initialization

Layer / File(s) Summary
Configure hash-table memory context
contrib/ivorysql_ora/src/builtin_packages/dbms_lock/dbms_lock.c
Adds utils/memutils.h and configures hash_create to use TopMemoryContext with HASH_CONTEXT.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to b2816

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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the fix for the dangling DBMS_LOCK hash table caused by per-query memory allocation.
Linked Issues check ✅ Passed The changes allocate the DBMS_LOCK hash table in TopMemoryContext and use HASH_CONTEXT, satisfying issue #1604 objectives.
Out of Scope Changes check ✅ Passed The three code changes directly address the linked issue and introduce no unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.
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.

DBMS_LOCK private hash table is built in a per-query context and dangles after the query ends

1 participant