Project

General

Profile

Actions

Bug #15862

closed

Segmentation fault when running Rails commands

Added by destrozates (Socrates Medina) almost 5 years ago. Updated almost 5 years ago.

Status:
Third Party's Issue
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.3p62 (2019-04-16 revision 67580) [armv7l-linux-eabihf] and ruby 2.5.5p157 (2019-03-15 revision 67260) [armv7l-linux-eabihf]
[ruby-core:92715]

Description

I´ve been trying to install rbenv, ruby and rails in my Raspberry Pi 3 B+ in the past couple of days and after some issues here and there, I've managed to get everything installed with no errors

With rbenv I installed both Ruby 2.6.3 and Ruby 2.5.5
Using Rails 5.2.3

and with both ruby versions I am getting the same problem when I execute the command:

rails server

Steps to reproduce

  1. On a Raspberry Pi install rbenv using brew
brew install rbenv
  1. Then use the following command to install ruby
rbenv install 2.6.3
  1. Then install rails:
gem install rails -v 5.2.3
  1. Create a new folder to hold your application and go to that folder:
$ cd                  # Change to the home directory.
$ mkdir environment     # Make a environment directory.
$ cd environment/       # Change into the environment directory.
  1. Use rails to create the application inside the previous folder:
rails _5.2.3_ new hello_app
  1. Go to the recently created 'hello_app' folder
cd hello_app
  1. Start the rails server
rails server

Expected behavior

pi@raspberrypi:~/environment/hello_app $ rails server
=> Booting Puma
=> Rails application starting on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server

And then it should just stay there to be able to access the web app on the address indicated

Actual behavior

First, the output shows this:

pi@raspberrypi:~/environment/hello_app $ rails server
=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options

And then the contents of the text file in the next link are shown.

Here is a link with the whole output:

https://www.dropbox.com/s/gjgo81zqeekfnvt/railsservererror.txt?dl=0

System configuration

Ruby version: I´ve tried with both 2.6.3 and Ruby 2.5.5
Rails version: I've tried with 6.0.0.rc1 and with 5.2.3
Puma version: I've tried with 3.12.1 and a previous one too

Workaround

User @dannyfallon (Danny Fallon) helped me with a workaround and explanation as follows from the Puma github site because I thought this was an issue with the Puma web server, but I was wrong:

According to your segfault's Control frame information you never even reached Puma. I would think that since Puma was never reached if you swapped puma in your gemfile for thin or webrick you still wouldn't be able to run rails server.

When you run rails server the application does a bunch of stuff before actually passing off the Rails::Application to a Rack server to run. In development Rails creates an EventedFileWatcher to watch for file changes so it can reload your app without you having to stop/start your server all the time. This uses the listen gem, which under the hood uses some OS-specific file events so it doesn't have to keep polling. In trying to create a watch (which listen does through rb-inotify for Linux), Ruby encountered a segmentation fault:

/home/pi/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/rb-inotify-0.10.0/lib/rb-inotify/notifier.rb:57: [BUG] Segmentation fault at 0xe92d000e
ruby 2.5.5p157 (2019-03-15 revision 67260) [armv7l-linux-eabihf]

-- Control frame information -----------------------------------------------
c:0095 p:---- s:0527 e:000526 CFUNC  :inotify_init
c:0094 p:0041 s:0523 e:000522 METHOD /home/pi/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/rb-inotify-0.10.0/lib/rb-inotify/notifier.rb:57 [FINISH]

Because rb-inotify is using FFI and some C functions, when things go wrong it does tend to blow up badly with segmentation faults.

There's lots of stuff you can do if you want to go deeper like report a bug over at FFI, attempt to recompile Ruby from source, test inotify on your distro outside of Ruby but you probably just want to get on with some development given you've been at it a few days.

I believe to fix this you can open config/development.rb and replace this:

  # Use an evented file watcher to asynchronously detect changes in source code,
  # routes, locales, etc. This feature depends on the listen gem.
  config.file_watcher = ActiveSupport::EventedFileUpdateChecker

with

  # Use a simple file watcher to detect changes in source code
  config.file_watcher = ActiveSupport::FileUpdateChecker

Caveat: The EventedFileWatcher is supposed to use OS events to detect file changes. The
FileWatcher will poll for changes. This may slow down reloads or cause higher system load.

Originally posted by @dannyfallon (Danny Fallon) in https://github.com/puma/puma/issues/1797#issuecomment-493190148

The solution proposed by @dannyfallon (Danny Fallon) actually allowed me to start the Web Server, but I was wondering if the people here at rb-inotify could give me a hand to try to figure out what went wrong and if there is anything I can do to fix this problem and be able to use

config.file_watcher = ActiveSupport::EventedFileUpdateChecker

Sorry for the long post...

Awaiting your comments.

P.S.: by the way, I get the same segmentation fault when I try to create a new rails app with rails version 6.0.0.rc1:

rails _6.0.0.rc1_ new hello_app

but if I use version 5.2.3 I don´t get the error

rails _5.2.3_ new hello_app

I also get the segmentation fault when I try to execute the following rails command:

rails generate scaffold User name:string email:string

Thanks,

Updated by mame (Yusuke Endoh) almost 5 years ago

  • Status changed from Open to Third Party's Issue

I think this issue is a bug or spec of rb-inotify. If it is a bug, it should be fixed. If it is a spec, rails should not use rb-inotify in such an environment. Anyway, you have already filed a ticket in that bug tracker: https://github.com/guard/rb-inotify/issues/94. Please want for the answer.

This tracker is for discussing a bug and feature of ruby itself. I'm unsure what you want to discuss in this ticket. I'm closing this as Third Party's Issue. Let me know if you have any specific topic about ruby itself.

Updated by destrozates (Socrates Medina) almost 5 years ago

mame (Yusuke Endoh) wrote:

I think this issue is a bug or spec of rb-inotify. If it is a bug, it should be fixed. If it is a spec, rails should not use rb-inotify in such an environment. Anyway, you have already filed a ticket in that bug tracker: https://github.com/guard/rb-inotify/issues/94. Please want for the answer.

This tracker is for discussing a bug and feature of ruby itself. I'm unsure what you want to discuss in this ticket. I'm closing this as Third Party's Issue. Let me know if you have any specific topic about ruby itself.

Thanks for your answer, and sorry for my late reply. I just wanted to be sure that this is not a Ruby issue. Can we say that we are sure about that?

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

destrozates (Socrates Medina) wrote:

Thanks for your answer, and sorry for my late reply. I just wanted to be sure that this is not a Ruby issue. Can we say that we are sure about that?

We may not be 100% sure, but the segmentation fault happens in a function (inotify_init) in a external C extension . It is far more likely to be an issue with the rb-inotify gem than an issue in Ruby. If you can reproduce the segmentation fault without using a C extension, or can provide example C code that uses the Ruby C-API that reproduces the segmentation fault, please open a new issue with example code.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0