Skip to content

Return an error when parsing runs out of memory - #394

Open
R3gardless wants to merge 1 commit into
pganalyze:18-latestfrom
R3gardless:fix-oom-fatal
Open

R3gardless wants to merge 1 commit into
pganalyze:18-latestfrom
R3gardless:fix-oom-fatal

Conversation

@R3gardless

Copy link
Copy Markdown

Part of #389.

When parsing runs out of memory, the PG_CATCH blocks in pg_query_parse.c call CopyErrorData() while everything the parser allocated is still there. That allocation fails as well, outside of PG_TRY, so the error is promoted to FATAL and the process exits.

This parses in a child context and deletes it before copying the error data, and resets the context before copying it in the JSON and protobuf output. With the reproduction from the issue, pg_query_parse(), pg_query_parse_protobuf() and pg_query_fingerprint() now return an "out of memory" error at 300MB and 600MB instead of exiting. make test passes with and without Valgrind.

pg_query_parse_plpgsql() and the fingerprinting step itself need similar changes. I left them out to keep this small, and can send a follow-up if this approach looks fine to you. The protobuf segfault at 1200MB is a separate problem.

The PG_CATCH blocks copied the error data in the same memory context that
had just run out of memory, so the allocation failed again outside of
PG_TRY and the error was promoted to FATAL, terminating the process.

Parse in a child context and delete it before copying the error data, and
reset the context before copying it in the JSON and protobuf output too.
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.

1 participant