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 o
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.
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.
@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.
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.
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.
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')])