Ruby’s debugging story has improved dramatically in 3.x (and Rails).
I figured the best way to understand what’s happening in Campfire would be to attach the debugger and step through some of the more interesting parts.
Unfortunately, I was greeted with a recurring error that often looked something like this:
At first, I was convinced that debugging was busted on my computer. But I spun up a new project, and everything worked as expected.
Then, I thought about the error above showing up multiple times and the problems with threads I had previously mentioned.
I restarted the process without cluster mode enabled for Puma (WEB_CONCURRENCY=0) and could connect the debugger as expected.
From here, I decided to compare the puma.rb file in Campfire to the one in the empty Rails 7.1 project I just spun up, and I found the problem.
In the Puma configuration file, cluster mode is enabled if
workers is greater than 0.
In a fresh Rails 7.1 puma.rb file, the worker configuration looks like this:
However, in Campfire, the RAILS_ENV check is removed
My guess is that with Campfire being a chat app with lots of connectivity, they opted for Puma’s cluster mode by default.
The good news is you can disable cluster mode in Campfire without changing any source. Just set the WEB_CONCURRENCY ENV to 0.
Something like this should do the trick:
WEB_CONCURRENCY=0 rdbg -n --open=vscode -c -- bin/rails server -p 3000