Skip to content

PG-2395 Make it clear we do not do any catcache looksups in ExecutorEnd - #811

Draft
jeltz wants to merge 2 commits into
percona:mainfrom
jeltz:catcache-in-exectorend
Draft

PG-2395 Make it clear we do not do any catcache looksups in ExecutorEnd#811
jeltz wants to merge 2 commits into
percona:mainfrom
jeltz:catcache-in-exectorend

Conversation

@jeltz

@jeltz jeltz commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

We may have potentially fixed #651 in d25da64.

One of our users reported a likely use after free bug on Amazon RDS that we could not reproduce where queryDesc->totaltime was freed when we accessed it. And while we failed to reproduce the bug a theory of ours is that in some cases a catalog cache lookup in ExecutorEnd could cause interrupts to be processed which then would for unknown reasons cause the totaltime object to be freed.

If this theory is correct then as we no longer do any catalog cache lookups in the ExecutorEnd hook then the bug should be gone. This is of course all very speculative.

Additionally this PR changes the code to make it 100% clear that no lookups can happen even though d25da64 should already have solved that,

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.50%. Comparing base (d25da64) to head (85ce181).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #811      +/-   ##
==========================================
+ Coverage   88.47%   88.50%   +0.03%     
==========================================
  Files           3        3              
  Lines        1301     1305       +4     
  Branches      180      181       +1     
==========================================
+ Hits         1151     1155       +4     
  Misses         75       75              
  Partials       75       75              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jeltz
jeltz force-pushed the catcache-in-exectorend branch 2 times, most recently from 6649865 to d22cc56 Compare August 3, 2026 23:24
@jeltz
jeltz marked this pull request as ready for review August 3, 2026 23:24
jeltz added 2 commits August 4, 2026 01:44
As the query stats object is now guaranteed, since commit
d25da64, to have been created in the
ExecutorStart hook there is no need to also try to create it in the
ExecutorEnd hook. This makes to code clearer for the reader, plus makes
it obvious that we no longer can do any catcache updates before
accessing the totaltime object.
One of our users reported a likely use after free bug on Amazon RDS that
we could not reproduce where queryDesc->totaltime was freed when we
accessed it. And while we failed to reproduce the bug a theory of ours
is that in some cases a catalog cache lookup in ExecutorEnd could cause
interrupts to be processed which then would for unknown reasons cause
the totaltime object to be freed.

If this theory is correct then as we no longer do any catalog cache
lookups in the ExecutorEnd hook then the bug should be gone. This is of
course all very speculative.

Bug report: percona#651
@jeltz
jeltz force-pushed the catcache-in-exectorend branch from d22cc56 to 85ce181 Compare August 3, 2026 23:44
Comment thread src/pg_stat_monitor.c
stats = pgsm_get_query_stats(queryId, planid, queryDesc->sourceText, queryDesc->operation);
/* We know at least pgsm_ExecutorStart() has created query stats */
stats = pgsm_get_query_stats(queryId);
Assert(stats != NULL);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is likely wrong. We should probably move to a stack instead.

@jeltz
jeltz marked this pull request as draft August 5, 2026 10:55
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.

SIGSEGV in pgsm_ExecutorEnd at pg_stat_monitor.c:781 during PortalCleanup (PG 18.3, correlates with autovacuum)

1 participant