Skip to content

Commit

Permalink
Clear errinfo after each finalizer runs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
headius committed Aug 9, 2022
1 parent 3c46159 commit 238bcbd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,12 @@ public void finalize() {

private void callFinalizer(IRubyObject finalizer) {
ThreadContext context = finalizer.getRuntime().getCurrentContext();
sites(context).call.call(context, finalizer, finalizer, id);
try {
sites(context).call.call(context, finalizer, finalizer, id);
} finally {
// clear last error so it is not seen by future finalizers
context.setErrorInfo(context.nil);
}
}
}

Expand Down

0 comments on commit 238bcbd

Please sign in to comment.