New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jruby 9.3.x: stacktrace is extended on each raise #7187
Comments
Nice find! |
Yup that is pretty weird! |
Something appears to be amiss with how we handle assigning the cause, and it keeps stacking them up. Cause support was added in 9.2. |
Ok so this is not really a problem with This would eventually be a memory leak if the same script engine invocation kept repeatedly raising a new exception, since they would endlessly stack up. A simple fix would be to clear the in-flight exception (in the current thread's ThreadContext) upon it being bubbled out of the scripting engine (or container, which I have not tested yet). However, this would break the ability to go back and query the current in-flight exception, which is used at minimum in the tests and potentially in user code that expects the magic A workaround for you would be to clear this value yourself, probably by evaluating code like This is a question of how far out from Ruby execution the in-flight exception should remain in scope. I am generally in favor of having it cleared once it has been raised out of the engine into the Java caller. |
Without clearing this, repeated raises in the same runtime will stack up causes, as reported in jruby#7187. This does affect a user's ability to query $! from Java whether using the ScriptingContainer or the javax.script APIs. Fixes jruby#7187
Without clearing this, repeated raises in the same runtime will stack up causes, as reported in jruby#7187. This does affect a user's ability to query $! from Java using javax.script APIs. Fixes jruby#7187
I've pushed two possible fixes plus a test based on @AlBundy33's in #7203. Surprisingly, it does not fail any of the test suites I expected it to fail. |
@headius so prior to 9.2 this was how this worked right? We did not have a cause. If so then it seems we are largely just reverting back to original behavior. |
believe this is an IR issue - as identified above the |
@enebo That is a good point, but I was more worried about clearing $! when it might be queried from Java, which has been the case for some time. However @kares points out that we may be setting it unnecessarily. @kares If that is the case then we should try to pare this back to just set it when entering a handler, but I feel like that misses cases. For example, I believe we have code where we expect it to also be set even if it does not enter a Ruby rescue block, so we can query it from Java based impls of Ruby core methods. |
This issue seems to be introduced in jruby 9.3.0.0 and still exists in latest 9.3.4.0.
9.2.20.1 seems not to be affected.
If you call a script multiple times that raises an error the stacktrace gets bigger and bigger.
for example call a script
raise 'foo'
in java, catch the error and then call another scriptraise 'bar'
(or the same as before).In jruby 9.2.x the second stacktrace looks like this
in jruby 9.3.x the second stacktrace looks like this
Here is a simple test-case
tested with jruby.jar from
https://repo1.maven.org/maven2/org/jruby/jruby-dist/9.3.4.0/jruby-dist-9.3.4.0-bin.zip
https://repo1.maven.org/maven2/org/jruby/jruby-dist/9.2.20.1/jruby-dist-9.2.20.1-bin.zip
The text was updated successfully, but these errors were encountered: