There's a good chance this is a Ruby bug with the way it deals
with process management, but I'm posting it here because Rails is
the only place it affects me. Now I know the issue, I can work
round it, but it's something caused me a hell of a lot of
frustration trying to track this down.
I had issues with Ctrl + C not working in "rails console" (it
wasn't working), and occasionally I found "reload!" and some
methods freezing up Ruby. (I had to use kill -9 to terminate
things, a normal 'kill' didn't work. I went down alsorts of paths
looking at gems, etc. After several hours I realised the issue went
away if I booted into Maverick's kernel (2.6.35) instead the natty
kernel (2.6.38). After more fiddling I also found that changing my
database.yml also got round the issue. It turns out the call to
hostname in some ERB in my database.yml was the cause
after 3-4 hours of hair pulling!
I'm running Ruby trunk, Rails 3.0.7, and Ubuntu Natty.
To replicate the issue:
On natty and Rails 3.x, create a new project 'rails new tester'.
Edit config/database.yml and put echo in
config/application.rb, then run "rails console". Try and press Ctrl
+ C once loaded, it probably won't do anything. Loading irb
normally and pressing Ctrl + C will work fine.
While the loack of Ctrl + C is merely an annoyance, I find that
if you use backticks in code that runs after "reload!" is called,
or use backticks a lot in general, the console seems to lock up
very randomly and that kill -9 is needed. This doesn't happen if I
revert back to Maverick kernel, 2.6.35.
As a result, I guess this is a corner case
shell-spawning/process/threading issue in Ruby itself, and not
Rails. However I only seem to replicate this is Rails for now,
hence reporting. It seems the Dependency system in ActiveSupport is
what triggers this, as I can't replicate this in irb.
I'm guessing some other people will have report
process/threading issues like what I've mentioned above but
obviously manifest very differently depending on how their code
utilises backticks.
Hopefully someone smarter than me will be see what is happening
and will be able to pass this upstream to the Ruby devs, explaining
to them a way to replicate it without Rails so it can be fixed.
When my console instance locks up, if I attach strace to it I
get a constant loop of:
sched_yield() = 0