Question

I've encountered a WEBrick + Rails problem & I haven't been able to find anyone else with the same issue.

I run WEBrick in my Rails app with

$ rvmsudo rails server -p 80

then I leave it in a detached screen and log out. If I wait a few days, WEBrick stops serving requests, giving this every time someone tries to load the app:

ERROR ThreadError: can't create Thread (11)
    /home/pi/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:284:in `start'

Then when I try to stop the server and restart it with Control-C, sometimes it shows this and I have to press Control-C twice to kill it:

[2013-11-13 21:13:08] ERROR NoMethodError: undefined method `shutdown' for nil:NilClass
    /home/pi/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/handler/webrick.rb:25:in `shutdown'

I tried checking whether my server has enough resources—plenty of RAM, CPU, disk space, swap, and network I/O to spare. Everything looks almost the same as when Rails is running normally (it's a really simple app).

Software & hardware details: Rails 4.0.1 with ruby 2.0.0p247 (2013-06-27 revision 41674) [armv6l-linux-eabihf] running on a Raspberry Pi with the latest Raspbian.

Source of my app is on GitHub. It's running at http://door.servebeer.com/.

Thanks in advance for your help!

Was it helpful?

Solution

I had a suspicion that I was hitting some kind of limit not related to the resources of the Pi. I noticed that, every time I reloaded the app in my browser, three new Ruby threads would be spawned.

Running this forkbomb-like test, I found that Ruby on the Pi can run about 300 threads before giving ThreadErrors. So after every ~100 pageviews, the server would stop serving pages because it had hit the thread limit.

This appears to be a problem with running ARM (probably another one of WEBrick's bugs). When I ran this with Rails 4.0.1 and Ruby 2.0.0 on an Intel Ubuntu server, the threads didn't stay open.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top