Skip to content

Conversation

@NJrslv
Copy link

@NJrslv NJrslv commented Dec 9, 2025

What does this PR do?

This PR fixes a crash, std::terminate(), caused by an exception occurring in the catch block of GPOPTOptimizedPlan() during gpopt_context.CloneErrorMsg().

When CloneErrorMsg fails (typically due to OOM), it throws a gpdb error, causing std::terminate().

Postgres has graceful error handling for errors that occur while processing other errors - even during OOM, the ErrorContext has reserved space to preserve error messages.

So rethrow the error to postgres handler.

Test Plan

Added a new test to the regression gporca_fault test.

I added a query that errors out during optimization in orca and as the result falls into catch block where another exception in CloneErrorMsg is thrown via inject fault.

Previously it resulted in the std::terminate() call & process crashing. Now catch the exception and let the postgres handle it with reserved buffer to preserve error message.

Impact

Instead of

server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

postgres reports an error (in case of OOM we will see it, not std::terminate with exiting processes):

ERROR:  ...

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hi, @NJrslv welcome!🎊 Thanks for taking the effort to make our project better! 🙌 Keep making such awesome contributions!

@NJrslv
Copy link
Author

NJrslv commented Dec 19, 2025

lets just get this commit from apache/cloudberry apache@c305e7b

2 similar comments
@NJrslv
Copy link
Author

NJrslv commented Dec 19, 2025

lets just get this commit from apache/cloudberry apache@c305e7b

@NJrslv
Copy link
Author

NJrslv commented Dec 19, 2025

lets just get this commit from apache/cloudberry apache@c305e7b

@NJrslv NJrslv closed this Dec 19, 2025
@NJrslv NJrslv deleted the njrslv-fix-std-terminate branch December 19, 2025 11:04
NJrslv added a commit that referenced this pull request Jan 15, 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