Skip to content

Commit 0cc14fd

Browse files
committed
[GR-32011] Disallow side-effecting safepoints for killOtherFibers()
PullRequest: truffleruby/2741
2 parents 1a813d3 + abc994a commit 0cc14fd

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/main/java/org/truffleruby/core/fiber/FiberManager.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.concurrent.CountDownLatch;
1515

1616
import com.oracle.truffle.api.TruffleContext;
17+
import com.oracle.truffle.api.TruffleSafepoint;
1718
import org.truffleruby.RubyContext;
1819
import org.truffleruby.RubyLanguage;
1920
import org.truffleruby.core.DummyNode;
@@ -356,11 +357,19 @@ public void killOtherFibers() {
356357

357358
// This method might not be executed on the rootFiber Java Thread but possibly on another Java Thread.
358359

359-
final TruffleContext truffleContext = context.getEnv().getContext();
360-
context.getThreadManager().leaveAndEnter(truffleContext, DummyNode.INSTANCE, () -> {
361-
doKillOtherFibers();
362-
return BlockingAction.SUCCESS;
363-
});
360+
// Disallow side-effecting safepoints, the current thread is cleaning up and terminating.
361+
// It can no longer process any exception or guest code.
362+
final TruffleSafepoint safepoint = TruffleSafepoint.getCurrent();
363+
boolean allowSideEffects = safepoint.setAllowSideEffects(false);
364+
try {
365+
final TruffleContext truffleContext = context.getEnv().getContext();
366+
context.getThreadManager().leaveAndEnter(truffleContext, DummyNode.INSTANCE, () -> {
367+
doKillOtherFibers();
368+
return BlockingAction.SUCCESS;
369+
});
370+
} finally {
371+
safepoint.setAllowSideEffects(allowSideEffects);
372+
}
364373
}
365374

366375
private void doKillOtherFibers() {

0 commit comments

Comments
 (0)