23

I have a Rails 6 api-only application which I am failed to run at AWS Elastic Beanstalk. After deployment of that application, puma stucks with message "Early termination of worker". I don't have any custom configurations nor settings for that project. Simply created an environment and uploaded archived zip file.

After I kill puma processes with command pkill -9 -f puma my puma.log file looks like below:

=== puma startup: 2020-01-22 13:17:45 +0000 ===
=== puma startup: 2020-01-22 13:17:45 +0000 ===
[28858] Early termination of worker
[28856] Early termination of worker
[28862] Early termination of worker
[28865] Early termination of worker
[28869] Early termination of worker

I searched that error and found nothing for solve.

  • Ruby version: 2.6.5
  • Puma version 4.3.1
  • Rails version: 6.0.2.1

I am using Puma with Ruby 2.6 running on 64bit Amazon Linux/2.11.2 on AWS.

yigit
  • 253
  • 1
  • 3
  • 8

6 Answers6

25

For the recent update from version 3.1.1 to 3.1.2 of the Ruby 2.6 running on 64bit Amazon Linux 2 platform, after checking the puma log in /var/log/puma/puma.log in my EC2 instance, it shows what you mention:

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

so, for checking what the actual error is, I entered my app's code folder /var/app/current and ran

pumactl start

this shows the actual error:

[XXXXX] Unable to load application: Gem::LoadError: You have already activated nio4r 2.5.3, but your Gemfile requires nio4r 2.5.2. Prepending `bundle exec` to your command may solve this.

So, since it says that there is a conflict of nio4r versions, I fixed it by forcing nio4r version to 2.5.3 adding this to my Gemfile:

gem 'nio4r', '2.5.3'

and then running bundle update, commiting and pushing changes and deploying.

Fito
  • 478
  • 4
  • 10
  • 1
    definitely running pumactl start helped me get the actual error message! – James May 12 '21 at 09:44
  • 1
    thanks for showing how to get the actual error! – Artur Haddad Jul 30 '21 at 21:13
  • 1
    I was able to see my issue using `rackup config.ru` – CTS_AE Aug 18 '21 at 17:26
  • 2
    I bet adding a `Procfile` would have helped you (`web: bundle exec puma -C /opt/elasticbeanstalk/config/private/pumaconf.rb`). Added `bundle exec` to the [default one](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ruby-platform-procfile.html). – x-yuri Sep 10 '21 at 05:29
10

Met the same error. Turns out it is a different PATCH of puma.

I was using this stack from elastic beanstalk

Ruby 2.6 AL2 version 3.0.1
64bit Amazon Linux 2 v3.0.1 running Ruby 2.6
Ruby 2.6.6-p146
RubyGems 3.1.2
Puma 4.3.3
...

My project's Gemfile included puma this way.

gem 'puma', '~> 4.3.3'

My project was a boilerplate for new projects that were coming my way, so things were working fine for "old" projects until the newer patch version, puma 4.3.5 as of now, came out.

Solution is to fix the version of the gem in the Gemfile as such:

gem 'puma', '= 4.3.3'

Lesson learnt is to always match your environment with that of your deployment tool. Keep track of the latest solution stack versions here.

Vic
  • 1,512
  • 17
  • 25
  • 1
    See the [other answer](https://stackoverflow.com/a/64352824/52499). In my case adding a `Procfile` helped (`web: bundle exec puma -C /opt/elasticbeanstalk/config/private/pumaconf.rb`). Added `bundle exec` to the [default one](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ruby-platform-procfile.html). – x-yuri Sep 10 '21 at 05:26
7

Happens when Puma can't start.

Good News, you can run

bundle exec puma -p 3000 -e production

locally and then you get verbose errors.

I personally discovered a :optional tag on a has_many and some delayed_job issues that was breaking mine. So there is no one fix for this.

bryanfeller
  • 336
  • 4
  • 8
2

@Vic's answer is helpful, and you should make sure you have locked in the right Puma version, but it didn't fix my problem. For me, the issue was that a piece of my code called Rails.application.credentials[...], and the credentials weren't setup on the Elastic Beanstalk instance.

I changed that code to just use ENV variables, e.g., ENV["MY_VAR"], and set those environment variables in the Elastic Beanstalk Configuration->Software settings page.

Unfortunately, nothing in the logs I could find told me this is where my app was crashing. I had to start with a bare-bones Rails install, and slowly bring over Gems and code from my original project. Each time I added a file, I would use eb deploy to confirm it worked, and finally narrow down the problem to the one particular file that didn't work.

jbnunn
  • 6,161
  • 4
  • 40
  • 65
0

I forgot to tell about my project structure. I have a directory called overrides in under app/ folder.

Finally, I found at that app/overrides folder causes puma crash maybe related with this issue: How to ignore a folder in Zeitwerk for Rails 6?

After I changed my environment.rb file with ignoring app/overrides folder, my project started to run smoothly.

yigit
  • 253
  • 1
  • 3
  • 8
0

My puma config had an "on_worker_boot" block that was attempting a db connection. In my case I have a primary + replica setup in rails. Removing this connection statement from our puma config resolves the Early termination of worker error.

ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[ENV.fetch('RAILS_ENV')])

  • Ruby version: 2.6.2
  • Puma version 4.3.5
  • Rails version: 6.0.3.2
johnsampson
  • 376
  • 3
  • 14