A production stack overflow error appeared after upgrading from Rails 7.1 to 7.2, caused by a change in how ActiveRecord builds OR queries. Rails 7.2 switched from iterative to recursive traversal of OR nodes, creating deep recursion with composite key queries containing many pairs. The issue was exacerbated by Async fibers having smaller stack sizes than threads. The problem was fixed in Rails 7.2.2 by flattening the OR node structure, but a workaround using simpler queries with in-memory filtering can be implemented for earlier versions.

7m read timeFrom bigbinary.com
Post cover image
Table of contents
Identifying the problemGoing into Rails InternalsThe Tree Structure ProblemThe Async ConnectionThe GitHub TrailOur SolutionMeasuring and VerifyingReferences

Sort: