2

I'm trying to run a Rails 6 app on AWS Elastic Beanstalk, but I get from puma log the following (repeats every few seconds)

[21776] + Gemfile in context: /var/app/current/Gemfile
[21776] Early termination of worker

The version numbers:

  • Rails 6.0.3.3
  • puma 4.3.5
  • ElasticBeanstalk Ruby 2.7 running on 64bit Amazon Linux 2/3.1.1
  • ruby 2.7.1p83

The server is unresponsive from outside the instance, and there's nothing on log/production.log.

Running on a dev machine on production mode there's no errors, and the database is reachable (no migration failure).

Running on the AWS instance the command bundle exec puma -p 3000 -e production I get

Puma starting in single mode...
Version 4.3.5 (ruby 2.7.1-p83), codename: Mysterious Traveller
Min threads: 5, max threads: 5
Environment: production
Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

so there's no obvious error that may cause the worker to halt.

How can I find out what's causing the workers to fail?

Edit 1:

I ran Rails console on the instance and found that the environment variables are missing - e.g. the production database user/pass/host. Once I hardcoded them I could connect to the database. I suspect the absence of other environment variables is making the app crash.

Dan
  • 63
  • 7
  • I do not think that EB uses port 3000 -- I would instead use $PORT environment variable. You might also need to check where the nginx instance is looking for your backend to be – nort Sep 22 '20 at 03:59

1 Answers1

1

A user on AWS forum had the answer.

Setting in my Gemfile

gem "nio4r", "= 2.5.2"

fixed the issue.

Dan
  • 63
  • 7
  • Thanks heaps for this! I wonder how we avoid something like this happening again in future? – Simon L. Brazell Oct 28 '20 at 00:25
  • @SimonL.Brazell AWS support recommend taking a separate branch and creating a parallel EB environment with the latest platform configuration and see if it works. They also said that they don't even have ssh access to the box so it's up to you to spot these problems. – Dan Oct 29 '20 at 01:03
  • but this happened to me without a deployment or anything, only the client noticed that the server was no longer responding and let me know, surely if the server isn't changing / disturbed it should just continue working right? – Simon L. Brazell Nov 01 '20 at 23:51
  • same happened to me: the box kept running as if nothing happened but the rails app wasn't responding. I detected the problem by elimination and found that puma was spawning workers and they kept dying. – Dan Nov 08 '20 at 09:31
  • I found [this](https://aws.amazon.com/blogs/devops/locally-packaging-gem-dependencies-for-ruby-applications-in-elastic-beanstalk/) detailing how to package gems with your application, not sure if this would solve the problem but I might give it a try. – Simon L. Brazell Nov 09 '20 at 10:07