Bug #15862
closedSegmentation fault when running Rails commands
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¶
- On a Raspberry Pi install rbenv using brew
brew install rbenv
- Then use the following command to install ruby
rbenv install 2.6.3
- Then install rails:
gem install rails -v 5.2.3
- 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.
- Use rails to create the application inside the previous folder:
rails _5.2.3_ new hello_app
- Go to the recently created 'hello_app' folder
cd hello_app
- 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 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 swappedpuma
in your gemfile forthin
orwebrick
you still wouldn't be able to runrails server
.When you run
rails server
the application does a bunch of stuff before actually passing off theRails::Application
to a Rack server to run. In development Rails creates anEventedFileWatcher
to watch for file changes so it can reload your app without you having to stop/start your server all the time. This uses thelisten
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 (whichlisten
does throughrb-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 in https://github.com/puma/puma/issues/1797#issuecomment-493190148
The solution proposed by @dannyfallon 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 6 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 6 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 6 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.