Commit 5ffcdd1f authored by Dylan Griffith's avatar Dylan Griffith

Workaround PGQuery.parse segfault again

This was causing problems again
https://gitlab.com/gitlab-org/gitlab/-/issues/342857 . We have taken the
same approach that was taken in
https://gitlab.com/gitlab-org/gitlab/-/blob/3b3dce4acc82e58fef7d2eccc80236061348c5a4/spec/support/database/prevent_cross_joins.rb#L39
parent f21f76b8
......@@ -79,8 +79,17 @@ module Database
return if cross_database_context[:transaction_depth_by_db].values.all?(&:zero?)
# PgQuery might fail in some cases due to limited nesting:
# https://github.com/pganalyze/pg_query/issues/209
#
# Also, we disable GC while parsing because of https://github.com/pganalyze/pg_query/issues/226
begin
GC.disable
parsed_query = PgQuery.parse(sql)
tables = sql.downcase.include?(' for update') ? parsed_query.tables : parsed_query.dml_tables
ensure
GC.enable
end
return if tables.empty?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment