Skip to content

Explicitly call #to_a to avoid potential GC bug

Kerri Miller requested to merge 352670-use-to_a-to-avoid-gc-bug-in-ruby into master

What does this MR do and why?

We've seen a small number of seg faults that look to be coming from this method. One candidate for a root cause is a known issue in Ruby's GC with Enumerable#flat_map (https://bugs.ruby-lang.org/issues/18140) because the concatenated array can be GC'd prematurely. By calling #to_a explicitly, we insert it into the Ruby stack so that GC can recognize it and keep it around.

There is a fix and backport for this in Ruby, but it may be a while before they're released.

h/t to @stanhu for identifying this as a possible root cause and supplying a solution.

Related fix in another library: https://github.com/pganalyze/pg_query/pull/227

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #352670

Edited by Kerri Miller

Merge request reports