Debugging Remote Processes With Pry-Remote

Highgroove really likes Pry. It’s a great tool for digging into your code and seeing what’s going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it. I recently ran into this situation when trying to debug an application that used Foreman to manage it’s processes. Luckily, the pry-remote project turned out to be a great solution.

When a process being run by Foreman hits a regular Pry breakpoint, the process will halt, but you will never be able to interact with the Pry session. This effectively freezes the app, forcing you to kill the Foreman process.

To work around this using pry-remote, you must first set it up in your project. First install the gem:

Once the gem is installed, you can now add a breakpoint in your application with binding.remote_pry. When the breakpoint is hit, pry-remote will block your app and open up a DRb endpoint that a client can connect to. Running pry-remote in a shell will then connect to the session and you’ll be able to interact with Pry as you normally would. Simply call exit in the Pry session to unblock the application.

Have you picked up any other tips or tricks while using Pry? Leave a comment below!