This project is archived and is in readonly mode.
connections not released in rails 3
-
Hemant Kumar
- Assigned user set to Aaron Patterson
Verified on Ruby 1.9. The problem with checkout methods is, it relies on return value of
waitmethod to reclaim connections from dead threads.But return value of
waithas been changed and in 1.9 it will return always true, whether it returns aftertimeoutperiod or it returns because it was signalled bysingal. In fact, return value ofwaitcan't be relied upon and I saw the code of Rubinius and JRuby implementations as well and behaviour is not analogous to 1.8.Attached patch fixes the problem and it no longer depends on return value of
waitmethod. I have also added some missing tests. One more thing that I did ended up doing was settingtimeoutvalue on1.9; original code hadtimeoutset tonilin Ruby 1.9. Callingwaitwithnilparameter can trigger deadlock as OP got in original bug report. -
Hemant Kumar
- Tag changed from rails 3.0.0, connection, pool, thread to rails 3.0.0, connection, patched, pool, thread
-
luis.lopez (at branelabs)
- Tag cleared.
The patch works. The only drawback is the waiting time to release connections. If you run the above code, it will freeze for 5 seconds in the 6th try. If you do the test more times (1.upto(20), for instance) it will freeze 5 seconds every 5 tries (since the pool is 5 for this test). Not sure if it is possible to check if there are connections to be reclaimed before wait.
-
gnufied
Well the patch does not modify original behaviour, it just makes it work on Ruby 1.9. One can of course check for connections held by dead threads before calling
wait,but that would mean that we will have to callclear_stale_cached_connectionstwice:clear_stale_cached_connections! if(@checked_out.size < @connections.size) next else @queue.wait(@timeout) end clear_stale_cached_connections! if @size == @checked_out.size raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it." end -
luis.lopez (at branelabs)
I personally think that it would be a better solution: the best moment to check for connections is probably before the wait and I don't think that call clear_stale_cached_connections twice would be big problem since there is a wait anyway. In the worst case there will be 2 calls to clear_stale_cached_connections (one more then in the current code) and in the best the wait would be avoided.
However, I don't know if clear_stale_cached_connections! could have a big performance penalty in case the pool were big
-
Repository
- State changed from new to committed
(from [444aa9c7350f243a6b4b2a3ff1601493a812872a]) fix ruby 1.9 deadlock problem, fixes #5736 add connection pool tests http://github.com/rails/rails/commit/444aa9c7350f243a6b4b2a3ff16014...
-
Repository
(from [2a04110f266b6ccaf94aeeae224af578a9620fbd]) fix ruby 1.9 deadlock problem, fixes #5736 add connection pool tests http://github.com/rails/rails/commit/2a04110f266b6ccaf94aeeae224af5...
