Rails App Silently Crashes on Ruby 2.4

  

I've been working recently to update RailsInstaller to use Ruby 2.4. It has taken a long time to get Ruby 2.4 working with RailsInstaller because starting RubyInstaller2, DevKit was replaced by MSYS2. That is a topic for another post though.

 

This is a story of a bug I encountered and I should have probably known the fix have I kept myself up to date on Ruby 2.4 changes.

The Problem

While working on RailsInstaller, I run the todo sample app from Engine Yard to make sure everything is working correctly. This time, the app crashes silently with a couple of warnings which you can see below.

In my previous role in the Engine Yard Support team, I enjoyed solving this type of problems. I pride myself in being methodical; I look for the solution of the immediate error instead of looking all over the place.

In this case, I don't see an error with a backtrace when running rails server. I ignore the warnings because in my experience they're not the cause of the issues. Because if they are, they shouldn't be warnings. It turns out these warnings are important. Read more to find out the solution.

C:\Sites\todo>bundle exec rails server
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
C:/RailsInstaller/Ruby2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
C:/RailsInstaller/Ruby2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated

C:\Sites\todo>

I see the same crash and warnings when I run rails console. I've never seen a Rails app crash without an error before so I try to figure out how to get the error to appear. I don't get anywhere with that so I change my approach.

C:\Sites\todo>bundle exec rails console
C:/RailsInstaller/Ruby2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
C:/RailsInstaller/Ruby2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated

C:\Sites\todo>

I really want to load the Rails app on the console because that's where I usually investigate. I check if there's another way to load the app. I find that irb works and looking at config.ru then environment.rb on the config directory, I run Rails.application.initialize which shows the error.

C:\Sites\todo>bundle exec irb -I.
irb(main):001:0> require 'config\application'
=> true
irb(main):002:0> Rails.application.initialize!
C:/RailsInstaller/Ruby2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
C:/RailsInstaller/Ruby2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated
SystemStackError: stack level too deep

The Solution

Turning to Google, I find that SystemStackError: stack level too deep is a known issue with Ruby 2.4 and some Rails 4.2 versions. Ruby 2.4 unifies Fixnum and Bignum to Integer and this causes issues with Rails apps older than 4.2.8.

I'm testing a Rails 4.2.0 app which shows the Fixnum and Bignum warnings. Upgrading to Rails 4.2.10 solves the issue.

If you are using Ruby 2.4, update your Rails apps to Rails 5. If you have to use Rails 4, update to the latest stable version, 4.2.10. If you have been waiting for Ruby 2.4 on RailsInstaller, keep an eye out for announcements soon.

Free Ebook:
Should I Hire DevOps or Outsource to a Provider?

You have to invest in your infrastructure: Do you hire DevOps for this critical function, assign it to your already overworked engineers, or outsource to a provider that offers full-stack capabilities?

Should I Hire DevOps?

Christopher Rigor

 
DevOps Support Manager, Asia-Pacific at Engine Yard. Organizer of @RubyConfPH. Speaker. Interested in automation, Kubernetes, Docker, Deis, ops, Ruby.
Find me on:

Comments

Subscribe Here!