Prying into a puma rails webserver effectively in single mode over docker

Prying into a puma rails web server effectively in single (non-cluster) mode over docker

Break points in rails web servers

History

Starting a rails server for debugging

class MyController < JSONAPI::ResourceController
  def create

    binding.pry

    payload = serializer.serialize_to_hash(new_resource_instance)
    render json: payload, status: :ok
  end

  ...
end

you would start a rails server using the rails server command

rails s

curl the endpoint, and trace through the stack in your rails console

Frame number: 0/99

From: /opt/demo-service/app/controllers/my_controller.rb @ line 4 MyController#create:

    2: def create
    3:   binding.pry
 => 4:   payload = serializer.serialize_to_hash(new_resource_instance)
    5:   render json: payload, status: :ok
    6: end

Adding puma

Now, when you run rails s, you’ll get something like

docker exec -it demo-service_apronfile_up_web  /bin/bash
root@c5ac60c6d5c7:/opt/demo-service# rails s -b 0.0.0.0
...
=> Booting Puma
=> Rails 5.0.6 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in cluster mode...
...
* Listening on tcp://0.0.0.0:3000
...
Frame number: 0/99

From: /opt/demo-service/app/controllers/my_controller.rb @ line 4 MyController#create:

    2: def create
    3:   binding.pry
 => 4:   payload = serializer.serialize_to_hash(new_resource_instance)
    5:   render json: payload, status: :ok
    6: end

Problem with binding.pry timeouts in cluster mode

Solution

Now, puma will start in single mode in development, and your debug session will remain active until you choose to exit

...
=> Booting Puma
=> Rails 5.0.6 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...