require() bombed my multi-threaded app!
summary
A Ruby app crashes under Sidekiq when autoloading mixes with manual requires causing double loads, constant redefinition warnings and hard-to-trace circular dependencies; Ruby 2 fixes autoload thread safety but ActiveSupport defaults to autoload vs require using Kernel.load which triggers repeats. Fixes: switch ActiveSupport to require, use eager_load_paths (not nested autoload paths), and adopt an isolated spec helper. Real results: three codebases drop test startup from 5–10 minutes to ~30 seconds; reproducing the original bug takes ~6 months of debugging.
AI-written summary · about
chapters (7)
- 0:00Introduction and setup
- 3:36Ruby code loading basics
- 15:27Active Support and autoloading
- 28:26Circular dependencies explained
- 31:58Rails autoload paths pitfalls
- 36:11Optimizing Rails test suites
- 39:01Best practices and takeaways
related talks
28mIn the beginning, there was "require"...
01h 04mCode is Required
47mConstant autoloading in ruby on rails
51mOpening Day 3 Keynote
29mRequire Hooks: Filling the Gap in Ruby's Extensibility
29mHow to Load 1m Lines of Ruby in 5s
38mLong journey of Ruby standard library
58mZeitwerk: A new code loader for Ruby
