This project is archived and is in readonly mode.
constant_watch_stack must be protected by a mutex
Reported by Charles Oliver Nutter | January 29th, 2009 @ 06:14 AM | in 2.x
For http://jira.codehaus.org/browse/... I investigated what looked like an Array being concurrently modified by multiple threads. The backtrace led me to active_support/dependencies.rb and the constant_watch_stack. This stack is an array updated during requires. Concurrent requires can cause the array to become corrupted under parallel Ruby implementations like JRuby.
The user provided the following script to reproduce it. It's not consistent, but with enough runs it does fail under JRuby:
require 'rubygems'
require 'active_record'
require 'thread'
require 'rexml/encoding'
#This will ensure activesupport will override Kernel.require
class MyTable < ActiveRecord::Base
set_table_name "table"
end
#build a test case with enough iterations to reproduce the problem.
#Since it's a race condition it'll occur randomly throughout the test
#
#if you can't reproduce the problem on your computer, try to increase the number of iterations
th = []
100.times do
th << Thread.new {
#this is what REXML is doing in $ruby_home/lib/ruby/1.8/rexml/encoding.rb (line 48)
require 'rexml/encodings/UTF-8.rb' #active_support will try to load the file
}
end
th.each do |t|
t.join
end
I whipped together a patch that adds a mutex alongside constant_watch_stack and uses it to synchronize all mutations and iterations over the stack. The patch is at http://gist.github.com/54401 and is against rails master@e6493eb9b76de73afef2706493efd090dfff4ecc.
Feel free to contact me with questions.
Comments and changes to this ticket
-
Charles Oliver Nutter January 29th, 2009 @ 06:27 AM
I confirmed the provided script fails on unpatched activesupport and succeeds (or at least succeeds for about an hour of my testing) on a patched activesupport. I used the following command line:
jruby -e "10000.times { system 'jruby test.rb' or fail }"
-
Charles Oliver Nutter January 29th, 2009 @ 06:34 AM
Ahh, contributor guides are nice. Re-attaching patch as format-patch.
-
Pratik January 30th, 2009 @ 03:35 PM
- Assigned user set to Jeremy Kemper
-
Repository January 30th, 2009 @ 04:27 PM
- State changed from new to committed
(from [ed0e5640879fd42c00fc5900e0355a0ea1dcf2ad]) Ensure constant_watch_stack is protected by a mutex, so concurrent requires do not corrupt it.
[#1816 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
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>
People watching this ticket
Attachments
Referenced by
- 1816 constant_watch_stack must be protected by a mutex [#1816 state:committed]