Open pierre opened 10 years ago
sounds like a Rails 4.1 thread-safety issue (maybe a regression in the AR 4.x series) ... best would be if there was some minimal ActiveRecord code to reproduce (possibly under JRuby)
Potentially related issue: https://github.com/killbill/killbill-plugin-framework-ruby/blob/master/lib/killbill/helpers/active_merchant/active_record/models/response.rb#L18 (timestamps not set).
Conceptually, the relevant code triggering the issue is equivalent to the following, but I wasn't able to reproduce it locally. Maybe switching to a JNDI connection would help?
require 'active_record'
=begin
create database ar_bug;
create user 'ar_bug'@'localhost' identified by 'ar_bug';
grant all on ar_bug.* to 'ar_bug'@'%' identified by 'ar_bug';
flush privileges;
=end
ActiveRecord::Base.establish_connection(
:adapter => 'jdbcmysql',
:username => 'ar_bug',
:password => 'ar_bug',
:driver => 'com.mysql.jdbc.Driver',
:url => 'jdbc:mysql://127.0.0.1:3306/ar_bug',
:pool => 251
)
ActiveRecord::Schema.define(:version => 1) do
create_table "ar_bugs", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "ar_linked_bugs", :force => true do |t|
t.integer "ar_bug_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end
class ArBug < ActiveRecord::Base
has_many :ar_linked_bugs
end
class ArLinkedBug < ActiveRecord::Base
belongs_to :ar_bug
end
threads = (1..250).map do
Thread.new do
1.upto(500) do
ActiveRecord::Base.transaction do
bug = ArBug.new
bug.save!
linked_bug = ArLinkedBug.new(:ar_bug_id => bug.id)
linked_bug.save!
end
end
end
end
threads.each { |thread| thread.join }
yy ... tried something similar even with some of the KB specific bits/helpers you have around. nevermind I'll give it one more shot and probably try to setup the whole thing later if there's no luck ...
The issue described here is still happening: https://github.com/killbill/killbill-plugin-framework-ruby/blob/e9530c1342776179b0a4135358f820517a721821/lib/killbill/ext/active_merchant/jdbc_connection.rb#L85
In the exception,
new_id
is set, butid
in the object is stillnil
.