This project is archived and is in readonly mode.
Rails 3.0.0.0RC Bug -- MySQL connection left in unusable state after MysqlAdapter.select and MysqlAdapter.select_rows -- with patch
Reported by Jeff Lawson | August 10th, 2010 @ 02:32 PM
When MysqlAdapter.select and MysqlAdapter.select_rows are used to call a stored procedure that returns a result set, the connection is left in a state that expects a further call to check for more results and, if necessary, to retrieve the next result, even though the desired result set has already been returned. Failure to tidy up the connection results in Mysql::Error: Commands out of sync when the connection is next used. Such a failure can be seen by calling ActiveRecord::Base.connection.active? which returns false, leading one to suspect that the connection was dropped when in fact the act of calling ActiveRecord::Base.connection.active? was itself an out of sync command and was responsible for the dropped connection. This explains why the current test_multi_results method in activerecord/test/cases/adapters/mysql/connection_test.rb neglects to call @connection.active? in the way the preceding tests do. My patch adds this call and the test passes once the problem is fixed.
The bug is easily fixed by adding the single statement that is commented below.
@connection.query_with_result = true
result = execute(sql, name)
rows = []
result.each_hash { |row| rows << row }
result.free
@connection.more_results && @connection.next_result # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else the connection will be dropped
rows
I have provided the fix plus a new test in the attached diff file.
I posted this more than a week ago under #3151 but it has not yet received attention, presumably as it has a milestone for 2.3.9 and most people are focussed on 3.0. I am concerned that this patch should make it to the 3.0 release.
Comments and changes to this ticket
-
Aaron Patterson August 17th, 2010 @ 09:17 PM
- State changed from new to committed
- Importance changed from to Low
Applied to master and 3-0-stable. Thanks! If this needs to be applied to the 2-3 branch, let me know.
-
Jeff Lawson August 17th, 2010 @ 09:47 PM
Thank you, Aaron :-)
Yes, the same patch does need to be applied to the 2-3 branch too.
-
Aaron Patterson August 17th, 2010 @ 09:51 PM
Hey Jeff,
I tried applying the patches to 2-3-stable and got conflicts. Would you mind porting them to 2-3-stable, and I'll apply?
-
Jeff Lawson August 18th, 2010 @ 03:46 PM
Hi Aaron,
Sorry about that problem.
Please find a 2-3-stable version of the patch attached :-)
-
Aaron Patterson August 18th, 2010 @ 04:34 PM
No problem! I've applied the patch. Thanks for porting it to 2-3-stable.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>