ENV[]= causes segfault when accessed concurrently from different runtimes
-------------------------------------------------------------------------
Key: JRUBY-5933
URL: https://jira.codehaus.org/browse/JRUBY-5933
Project: JRuby
Issue Type: Bug
Affects Versions: JRuby 1.6.3
Environment: MacOS 10.6.8
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
Reporter: Tobias Crawley
Assignee: Thomas E Enebo
With the changes in 1.6.3 that write any ENV changes through to the POSIX
layer, there is no the opportunity for a segfault if two runtimes in different
threads call ENV[]= concurrently.
To reproduce:
{code}
import org.jruby.Ruby;
import org.jruby.RubyInstanceConfig;
public class Boom {
public static void spinENV(String threadName) {
RubyInstanceConfig cfg = new RubyInstanceConfig();
try {
Ruby runtime = Ruby.newInstance( cfg );
int loop = 1;
while( true ) {
System.out.println( threadName + ": loop " + loop++ );
runtime.evalScriptlet("ENV['HAM'] = 'biscuit'");
runtime.evalScriptlet("ENV['biscuit'] = 'gravy'");
}
} catch (Exception ex) {
System.err.println( threadName + ex );
}
}
public static final void main(String[] args) throws Exception {
Thread t1 = new Thread() {
public void run() {
Boom.spinENV( "t1" );
}
};
Thread t2 = new Thread() {
public void run() {
Boom.spinENV( "t2" );
}
};
t1.start();
t2.start();
}
}
{code}
{noformat}
$ javac -cp ../jruby/lib/jruby.jar:. Boom.java
$ java -cp ../jruby/lib/jruby.jar:. Boom
t2: loop 1
t1: loop 1
java(58262,0x10da01000) malloc: *** error for object 0x1002001a0: double free
*** set a breakpoint in malloc_error_break to debug
Abort trap
{noformat}
Under 1.6.2, this will run until interrupted. It also runs fine under 1.6.3
with -Djruby.native.enabled=false.
If I set the 'updateRealENV' on the ENV hash to false with the following, the
issue goes away:
{code}
StringBuffer env_fix = new StringBuffer( "require 'java'\n" );
env_fix.append( "update_real_env_attr =
org.jruby.RubyGlobal::StringOnlyRubyHash.java_class.declared_fields.find { |f|
f.name == 'updateRealENV' }\n" );
env_fix.append( "update_real_env_attr.accessible = true\n" );
env_fix.append( "update_real_env_attr.set_value(ENV.to_java, false)\n"
);
runtime.evalScriptlet( env_fix.toString() );
{code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email