Skip to content

Hang on SIGTERM with ruby 2.6 in clustered mode #1755

@vbalazs

Description

@vbalazs

Steps to reproduce

  1. Create a config.rb file with this content and run mkdir -p tmp/pids
# frozen_string_literal: true

app_dir = File.expand_path(__dir__)

workers 4
threads 1, 8

bind "tcp://0.0.0.0:#{ENV.fetch('PORT', 3000)}"

pidfile "#{app_dir}/tmp/pids/puma.pid"
state_path "#{app_dir}/tmp/pids/puma.state"

app do |env|
  puts env
  body = 'Hello, World!'

  [200, { 'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }, [body]]
end
  1. puma -C config.rb
  2. Send a TERM signal to the cluster process
$ /bin/kill -TERM `cat tmp/pids/puma.pid`

Expected behavior

Gracefully shuts down workers

Actual behavior

Process hangs, requires KILL

System configuration

Ruby version: 2.6.2
Puma version: 3.12.1
Platform: Ubuntu 18.04 (4.15.0-1032-aws)

Additional info

It works with Ruby 2.5.5.

I discovered this using puma with systemd, it times out and kills the process after a certain time. I checked the signals docs, with INT is really working but from the documentation is not clear if I can just use this signal instead without any other side effect.

if in systemd service descriptor I set ExecStop=/bin/kill -INT $MAINPID , it seems to work but it throws this error like it tries to stop the server twice:

api-puma[28423]: [28423] - Gracefully shutting down workers...
api-puma[28423]: [28423] - Gracefully shutting down workers...
api-puma[28423]: /opt/myapp/shared/vendor/ruby/2.6.0/gems/puma-3.12.1/lib/puma/cluster.rb:40:in `waitpid': No child processes (Errno::ECHILD)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions