Skip to content

Spoc-465: LR issue due to spock can't find relation#384

Open
danolivo wants to merge 2 commits intomainfrom
spoc-465
Open

Spoc-465: LR issue due to spock can't find relation#384
danolivo wants to merge 2 commits intomainfrom
spoc-465

Conversation

@danolivo
Copy link
Contributor

@danolivo danolivo commented Mar 10, 2026

Fix stale local_tuple pointer in the INSERT exception path when the
relation is not found, preventing get_tuple_origin from dereferencing
freed memory
Prevent debug_query_string from producing garbage in apply worker logs
by initializing it to NULL at startup and clearing it in the SQL error
context callback to avoid duplicate output

Initialize debug_query_string to NULL at apply worker startup, since it
is not a regular backend and has no client query string.

Also clear debug_query_string in execute_sql_command_error_cb after the
errcontext call, which already includes the SQL statement, to prevent it
from appearing a second time in the LOG output.
When spock_read_insert returns NULL (relation not found), the exception
log entry's local_tuple may still hold a pointer from a previous
operation. Clear it before calling log_insert_exception to prevent
get_tuple_origin from dereferencing freed memory.
@danolivo danolivo self-assigned this Mar 10, 2026
@danolivo danolivo added the bug Something isn't working label Mar 10, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

📝 Walkthrough

Walkthrough

The pull request refines error handling and logging cleanup in the replication apply process. When an INSERT fails due to a missing relation, the local tuple pointer is cleared. Debug query strings are explicitly nullified in error callbacks and apply worker initialization to prevent duplicate or uninitialized logging output.

Changes

Cohort / File(s) Summary
Error Handling & Logging Cleanup
src/spock_apply.c
Clears local_tuple pointer after failed relation lookups in INSERT operations. Initializes and clears debug_query_string in error callback and apply worker initialization to prevent duplicate SQL statements and uninitialized memory references in logs.

Poem

🐰 A rabbit hops through logs so clean,
Clearing pointers, no leaks foreseen,
Debug strings vanish with care,
Error paths handled fair,
Replication streams flow pristine!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title references the ticket (Spoc-465) and describes the main issue about spock failing to find a relation, which aligns with the primary fix for the stale local_tuple pointer when INSERT fails due to missing relation.
Description check ✅ Passed The PR description directly addresses the changeset, explaining the specific fixes for stale pointer issues and debug logging cleanup.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch spoc-465

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 and usage tips.

@mason-sharp
Copy link
Member

Should this include 016_sub_disable_missing_relation.pl‎ that is in the other PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants