On Wed, Sep 8, 2010 at 1:27 AM, Yoko H. [email protected] wrote:
What’s odd about this is that the code is being called in a loop, and
works for several iterations before failing later. Â So $utilities must
have existed initially, and then vanished later on.
Needless to say, this is the only usage of $utilities in the entire
script. Â The value for it is put into the ScriptContext before the
script is executed and not touched at any other time.
So, did this happen when the script was evaluated using JSR223 impl?
Was the default configuration used?
Yes on both. We’re using JSR223 in a very generic way, with no
knowledge of JRuby specifically (the same code supports JavaScript and
I know at least one user who installed Jython themselves and is using
that.)
This sounds bug to me, but let me clarify how this happened. JSR223
requires no state should be remained after the evaluation. To fulfill
this requirement, JSR223 impl sets null to global vars on runtime that
are tied to vars in ScriptContext when the evaluation ends. The global
vars in ScriptContext should be set again for successive evaluation,
but this part seems to have a problem.
We do use a fresh ScriptContext for each run so I would expect them to
be isolated. But instead of asking whether this was actually the
case, I did an experiment.
Longer-running script:
20.times do
puts “$utilities = #{$utilities}”
sleep 5
end
Shorter-running script:
puts “shorter script run”
I start the longer-running script and then run the shorter one part
way through, and the output was quite mysterious:
$utilities = script.impl.DefaultUtilities@8864af
$utilities = script.impl.DefaultUtilities@8864af
$utilities = script.impl.DefaultUtilities@8864af
shorter script run
Script completed successfully with return value: null
Then a minute later:
Script completed successfully with return value: null
So it looks like the original context loses its output stream at the
time the second script either starts or completes.
I tried another one, this time calling a method, and bingo:
exporter = script.impl.exporter.DefaultExporter@1d2052b
exporter = script.impl.exporter.DefaultExporter@1d2052b
shorter script run
Script completed successfully with return value: null
Script failed due to an error:
C:\Scripts\Longer Running.rb:2: undefined method `exporter' for
nil:NilClass (NoMethodError)
from C:\Scripts\Longer Running.rb:1:in `times’
from C:\Scripts\Longer Running.rb:1
…internal jruby stack elided…
from (unknown).(unknown)(C:\Scripts\Longer Running.rb:1)
from Integer.times(C:\Scripts\Longer Running.rb:1)
from (unknown).(unknown)(:1)
For the sake of comparison, I tried writing the same script using
JavaScript to see what Rhino would do in this situation:
Longer running:
for (var i = 0; i < 20; i++) {
println("utilities = " + utilities.exporter);
java.lang.Thread.sleep(1000);
}
Shorter running:
println(“shorter script run”);
Rhino behaves as I would expect - the script contexts are isolated
from each other and the message continues to print after the short
script terminates.
TX
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email