Skip to content

Commit cb5d4fe

Browse files
committed
Fix exception due to shutdown hook race condition
1 parent 2cb89fc commit cb5d4fe

File tree

1 file changed

+6
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi

1 file changed

+6
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,12 @@ private void addNativeFinalizer(Env env, Object finalizeFunction, Object finaliz
621621
@TruffleBoundary
622622
public void finalizeCapi() {
623623
if (nativeFinalizerShutdownHook != null) {
624-
Runtime.getRuntime().removeShutdownHook(nativeFinalizerShutdownHook);
625-
nativeFinalizerRunnable.run();
624+
try {
625+
Runtime.getRuntime().removeShutdownHook(nativeFinalizerShutdownHook);
626+
nativeFinalizerRunnable.run();
627+
} catch (IllegalStateException e) {
628+
// Shutdown already in progress, let it do the finalization then
629+
}
626630
}
627631
}
628632

0 commit comments

Comments
 (0)