Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't capture hard errors in with-clause parser #7893

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkindahl
Copy link
Contributor

@mkindahl mkindahl commented Apr 1, 2025

When parsing WITH clause arguments for ALTER TABLE to extract compression parameters, syntax errors in the text format are caught using PG_TRY and PG_CATCH and then returning an indication if the parse succeeded or not.

If an out-of-memory error occurs inside execution of the input function and this error is caught, it can continue executing and potentially cause cascading out-of-memory errors and in the end exhausting the error stack.

This commit solves this by using checking the category of the thrown error and only allow errors in the data exception and the syntax errors and access rules violation category, which are "soft" errors in this case. Hard errors, like out-of-memory errors, are re-thrown allowing the backend to deal with it properly.

@mkindahl mkindahl added the bug label Apr 1, 2025
@mkindahl mkindahl self-assigned this Apr 1, 2025
Copy link

codecov bot commented Apr 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.90%. Comparing base (59f50f2) to head (5c62687).
Report is 869 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7893      +/-   ##
==========================================
+ Coverage   80.06%   81.90%   +1.83%     
==========================================
  Files         190      249      +59     
  Lines       37181    46154    +8973     
  Branches     9450    11573    +2123     
==========================================
+ Hits        29770    37801    +8031     
- Misses       2997     3790     +793     
- Partials     4414     4563     +149     

☔ View full report in Codecov by Sentry.
📢 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.

@mkindahl mkindahl force-pushed the dont-capture-hard-errors branch from a55c32a to d724332 Compare April 1, 2025 09:28
@mkindahl mkindahl requested a review from erimatnor April 1, 2025 09:30
@mkindahl mkindahl force-pushed the dont-capture-hard-errors branch 4 times, most recently from 7fc20c2 to fe5e185 Compare April 1, 2025 11:00
@mkindahl mkindahl marked this pull request as ready for review April 1, 2025 11:00
@mkindahl mkindahl force-pushed the dont-capture-hard-errors branch from fe5e185 to fc706ec Compare April 1, 2025 11:45
@mkindahl mkindahl requested a review from fabriziomello April 2, 2025 13:20
@mkindahl mkindahl changed the title Run input function allowing soft errors only Don't capture hard errors in with-clause parser Apr 2, 2025
@mkindahl mkindahl force-pushed the dont-capture-hard-errors branch from fc706ec to eb1d453 Compare April 2, 2025 14:01
@mkindahl mkindahl added this to the v2.19.2 milestone Apr 2, 2025
@mkindahl mkindahl force-pushed the dont-capture-hard-errors branch from eb1d453 to f476732 Compare April 2, 2025 14:11
@@ -161,12 +161,38 @@ parse_arg(WithClauseDefinition arg, DefElem *def)

Assert(OidIsValid(in_fn));

/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why all this pg_try-catch thing is needed?

I am asking because it looks like we are either rethrowing the error or just replacing it with another one. So why don't we just let the function call fail with whatever error it is throwing without capturing it?

Is it because we want to rewrite the error to something more user-friendly? I am wondering why we need to rewrite the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAICT, it was only added for rewriting the error to something more user-friendly (see 3ef6732).

@mkindahl mkindahl force-pushed the dont-capture-hard-errors branch 6 times, most recently from 9a53848 to da5e7b2 Compare April 5, 2025 12:47
@mkindahl mkindahl force-pushed the dont-capture-hard-errors branch from da5e7b2 to 1fa1462 Compare April 7, 2025 06:34
When parsing WITH clause arguments for ALTER TABLE to extract
compression parameters, syntax errors in the text format are caught
using PG_TRY and PG_CATCH and then returning an indication if the parse
succeeded or not.

If an out-of-memory error occurs inside execution of the input function
and this error is caught, it can continue executing and potentially
cause cascading out-of-memory errors and in the end exhausting the error
stack.

This commit solves this by using checking the category of the thrown
error and only allow errors in the data exception and the syntax errors
and access rules violation category, which are "soft" errors in this
case. Hard errors, like out-of-memory errors, are re-thrown allowing
the backend to deal with it properly.

It also adds tests and test utilities that allow you to raise an error
of an arbitrary category when converting a string to the type.
@mkindahl mkindahl force-pushed the dont-capture-hard-errors branch from 1fa1462 to 5c62687 Compare April 7, 2025 07:03
@philkra philkra modified the milestones: v2.19.2, v2.19.3 Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants