Blog

Thoughts from my daily grind

Ruby on Rails - Server hang/timeout inside Foreman

Posted by Ziyan Junaideen |Published: 08 June 2021 |Category: Ruby on Rails
Default Upload |

I have been a frequent user of the Ruby Gem Foreman for the last 8+ years as a Ruby developer. Foreman allows the management of applications that are based on a Procfile. However, I recently experienced an unusual scenario with Foreman in a Ruby on Rails 3 project I adopted. The application would hang (freeze, time-out, slow down) after loading pages a few times.

I first didn't suspect it was Foreman. I doubled checked the Chef cookbook I wrote and rebuilt the Vagrant VM. Upon further inspection, I noticed was that the last thing in the log file was a DB query. I installed PG from the Ubuntu repository manually to make sure it was not a Postgres issue. Nothing I did seem to fix the problem.

That is when I thought of using bundle exec to run the commands. This is something I usually do, but this profile was not by me. I remember Bjoern, the CTO of Orpiva, saying something about using bundle exec everywhere which is where my habit of using bundle exec ever where comes from.

The Procfile looked like this:

  cat Procfile.vagrant
web:        puma -C config/vagrant/puma.rb
resque:     rake environment resque:workers QUEUE=* INTERVAL=0.1 COUNT=2
scheduler:  rake resque:scheduler
faye:       rackup faye.ru -p 9080 -E production

I changed it to this:

  cat Procfile.vagrant
web:        bundle exec puma -C config/vagrant/puma.rb
resque:     bundle exec rake environment resque:workers QUEUE=* INTERVAL=0.1 COUNT=2
scheduler:  bundle exec rake resque:scheduler
faye:       bundle exec rackup faye.ru -p 9080 -E production

Voila, everything is working as it should. I took some time to write about this while I was improving the applications test coverage and prepare for a Rails 6.1 upgrade.

I am not sure what is happening, but it fixed it. I contacted the previous developer out of curiosity, and he said he had no such issue. But the only difference between his setup and mine was that I was using RVM, and he was using rbenv. I would have used rbenv myself, but I couldn't install Ruby 2.1.0 using it due to some OpenSSL issue, if I recall correctly.

So there it is. If you are also having issues with Ruby on Rails or any other Ruby application hanging up when using within Foreman, run them with bundle exec.

Tags
About the Author

Ziyan Junaideen -

Ziyan is an expert Ruby on Rails web developer with 8 years of experience specializing in SaaS applications. He spends his free time he writes blogs, drawing on his iPad, shoots photos.

Comments