-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
Better testing for finalization #935
Comments
In jruby#7267 we had a report of endless exception cause processing that turned out to be triggered by a bad finalizer (that allowed an exception to bubble out) stacking up causes from previous calls of that finalizer. The fix here mimics what CRuby does: where they reset the errinfo to what it was prior to the finalizer running (because CRuby's GC often/usually runs on the current user thread), we simply clear it after each finalizer has run (because the JDK runs finalizers on a separate thread, as will our future non-JVM-finalizer version of this logic). No spec is provided yet due to the difficulty of testing GC-triggered events across VMs. See ruby/spec#935 for more details. Fixes jruby#7267
We've tried in the past and it seems near-impossible to have a reliable test for this unfortunately. GC in a loop is also something I tried but it's 1) very slow 2) still doesn't finalize sometimes. My take is: no one should rely on finalizers on Ruby, they run unreliably (on all Ruby impls) and always late. Releasing resources should always be done promptly with an See spec/core/objectspace/define_finalizer_spec.rb Lines 4 to 10 in 8059e59
TruffleRuby also tried using TruffleRuby-specific methods but even that spuriously fails: |
One possibility might be to rely on the fact CRuby runs finalizers on exit, and use that as a way of testing finalizers aspects other than "they happen when the object is GC'd". |
In jruby#7267 we had a report of endless exception cause processing that turned out to be triggered by a bad finalizer (that allowed an exception to bubble out) stacking up causes from previous calls of that finalizer. The fix here mimics what CRuby does: where they reset the errinfo to what it was prior to the finalizer running (because CRuby's GC often/usually runs on the current user thread), we simply clear it after each finalizer has run (because the JDK runs finalizers on a separate thread, as will our future non-JVM-finalizer version of this logic). No spec is provided yet due to the difficulty of testing GC-triggered events across VMs. See ruby/spec#935 for more details. Fixes jruby#7267
While attempting to write a spec for jruby/jruby#7267 I ran into various issues and questions...
The spec I attempted is below, but only makes a best attempt at forcing GC-oriented finalization and still does not suppress the error output.
I don't want to leave the fix for jruby/jruby#7267 untested, but I'm unsure how we should move forward to improve the GC-triggered finalization specs.
The text was updated successfully, but these errors were encountered: