Closed nateless closed 9 years ago
My guess is simply that the ruby library for redis is not threadsafe (after opening the connection). But I'm not sure.
While reading this thread I was going to recommend Redis.new inside the handlers, but you had figured it out.
Spent whole day trying to figure out what's happening. We use Redis and initialize it at load in initialize file with global variable
$redis
. In controller we have something like this:At random time app freeze,
strace
shows:I've added another thread at rails initialization which just dumps Threads.list with backtrace for each of them each second, after some load (just open a lot of connections to site) app freeze and this is what I have [I've removed irrelevant threads]:
First backtraces
stream_controller.rb:45
refers to our line$redis.publish
inonopen
callback and second regarding$redis.publish
inonclose
.I've tried to change onopen and onclose callbacks to this version:
And at the moment it works fine, however the question is why it stuck in deadlock using global var?