Array#pack is no longer threadsafe
----------------------------------
Key: JRUBY-5728
URL: http://jira.codehaus.org/browse/JRUBY-5728
Project: JRuby
Issue Type: Bug
Components: Core Classes/Modules
Affects Versions: JRuby 1.6.1
Environment: independent - observed on windows and linux
Reporter: rich liebling
Attachments: jruby-bug.rb
The method Array#pack is no longer thread-safe. That is, if called on
different arrays in different threads it may not encode the array properly. In
particular, it may encode one array using the converter for another call.
I have attached a simple test program, which starts two threads each in a tight
loop calling pack and checking the result. But, they call pack with different
arguments. It will print each time it gets the wrong result. (NOTE: the
program will not terminate until you stop it w/CTRL-C or equivalent.)
Looking at the code in org.jruby.util.Pack.java, the issue arises here (line
1830 in jruby 1.6.0):
Converter converter = converters[type];
if (converter != null) {
executor.setConverter(converter);
idx = encode(runtime, occurrences, result, list, idx, executor);
continue;
}
the variable executor is really executor18, a static variable in this class.
Hence, it is shared across all calls to pack. But, this shared static variable
has state, in particular from executor.setConverter().
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
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