Skip to content

more exception barriers#87

Closed
serprex wants to merge 1 commit into
mainfrom
more-alloc-boundaries
Closed

more exception barriers#87
serprex wants to merge 1 commit into
mainfrom
more-alloc-boundaries

Conversation

@serprex

@serprex serprex commented May 6, 2026

Copy link
Copy Markdown
Member

extending #86

@serprex serprex requested a review from iskakaushik May 6, 2026 04:14
@serprex serprex force-pushed the more-alloc-boundaries branch 2 times, most recently from 046ed86 to 88c7b00 Compare May 7, 2026 04:56
@serprex serprex requested a review from JoshDreamland May 7, 2026 04:56
Base automatically changed from alloc-boundaries to main May 7, 2026 14:00
@serprex serprex force-pushed the more-alloc-boundaries branch from 88c7b00 to 318b11c Compare May 7, 2026 14:12
@JoshDreamland JoshDreamland force-pushed the more-alloc-boundaries branch from 318b11c to afbf183 Compare May 11, 2026 20:58
Copilot AI review requested due to automatic review settings May 11, 2026 20:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the exception-barrier approach from #86 by adding additional top-level try/catch guards in the bgworker-facing exporter entry points, aiming to prevent C++ exceptions (especially std::bad_alloc) from crossing PostgreSQL PG_TRY / longjmp boundaries.

Changes:

  • Wrap PschExporterInit() in try/catch to contain exceptions during exporter construction and initial connection.
  • Wrap PschExportBatch() in try/catch to contain exceptions during dequeue and export flow.
  • Wrap PschExporterShutdown() in try/catch to attempt to contain exceptions during exporter teardown.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/export/stats_exporter.cc Outdated
Comment on lines +372 to +377
elog(DEBUG1, "pg_stat_ch: PschExportBatch() called");
StatsExporter* exporter = g_exporter.exporter.get();

if (!exporter->IsConnected()) {
elog(DEBUG1, "pg_stat_ch: client is null, initializing");
if (!exporter->EstablishNewConnection()) {
Comment on lines +441 to +447
// Exception barrier: exporter destructors (clickhouse-cpp socket close, gRPC
// stub teardown, protobuf arena release) can throw. Catching here prevents the
// throw from crossing the on_proc_exit chain.
void PschExporterShutdown(void) {
g_exporter.exporter.reset();
try {
g_exporter.exporter.reset();
} catch (const std::bad_alloc&) {
@serprex

serprex commented May 12, 2026

Copy link
Copy Markdown
Member Author

this has NPE problems & is replaced by #94

@serprex serprex closed this May 12, 2026
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.

2 participants