Skip to content

Conversation

@NJrslv
Copy link
Contributor

@NJrslv NJrslv commented Dec 8, 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!

@reshke
Copy link
Contributor

reshke commented Dec 8, 2025

👍

@my-ship-it
Copy link
Contributor

Thanks for the PR, which is a good start 😄

@tuhaihe
Copy link
Member

tuhaihe commented Dec 17, 2025

That would be better to have a commit message title and message body when merging this PR. Can follow the template.

@NJrslv
Copy link
Contributor Author

NJrslv commented Dec 17, 2025

If I am not the one squashing and merging this PR, I have provided the commit message and body below for the merger to copy & paste

Fix std::terminate() crash in GPOPTOptimizedPlan()
Fix a crash occurring when CloneErrorMsg() fails (e.g. from OOM)
and throws an exception inside a catch block. Previously, this 
triggered std::terminate().

Now, rethrow the exception to the Postgres handler. Postgres reserves
memory to handle errors gracefully, ensuring the user receives an
error message instead of the process terminating.

Includes a new regression test with fault injection.

@reshke reshke merged commit c305e7b into apache:main Dec 19, 2025
121 of 128 checks passed
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.

5 participants