Open Math2 opened 12 months ago
Oops, actually if you #close
the statements, this works fine.
I believe I'm seeing a problem with threads and prepared statements that happens without prepared statements accumulating endlessly like this, but this isn't a way to reproduce it...
Very curious. This one fails with "Commands out of sync" exceptions while reusing the same prepared statements, but apparently only if the query returns 0 rows!
conf = { ... }
clients = 10.times.map { Mysql2::Client.new(**conf) }
stmts = clients.map { |client| client.prepare("SELECT 123 WHERE FALSE") }
loop do
stmts.map do |stmt|
Thread.new { stmt.execute }
end.each(&:join)
end
The problem was happening with a connection pool shared by many threads, but I found a simple way to reproduce it:
This immediately fails with "Commands out of sync; you can't run this command now (Mysql2::Error)" here (after 50 or so iterations of the outer loop).
With
#query
it works fine. It only fails with prepared statements.