Skip to content
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

Exception from ResourceManager at end of execution #6472

Closed
radeusgd opened this issue Apr 28, 2023 · 3 comments · Fixed by #7302
Closed

Exception from ResourceManager at end of execution #6472

radeusgd opened this issue Apr 28, 2023 · 3 comments · Fixed by #7302
Assignees
Labels
Milestone

Comments

@radeusgd
Copy link
Member

Recently when running Enso I got:

Exception in thread "Thread-14" java.lang.IllegalStateException: Language environment is already disposed.
        at org.graalvm.truffle/com.oracle.truffle.api.TruffleLanguage$Env.checkDisposed(TruffleLanguage.java:1671)
        at org.graalvm.truffle/com.oracle.truffle.api.TruffleLanguage$Env.submitThreadLocalInternal(TruffleLanguage.java:3462)
        at org.graalvm.truffle/com.oracle.truffle.api.TruffleLanguage$Env.submitThreadLocal(TruffleLanguage.java:3435)
        at org.enso.interpreter.runtime.ResourceManager.scheduleFinalizationAtSafepoint(ResourceManager.java:122)
        at org.enso.interpreter.runtime.ResourceManager$Runner.run(ResourceManager.java:201)
        at java.base/java.lang.Thread.run(Thread.java:829)
        at org.graalvm.truffle/com.oracle.truffle.polyglot.SystemThread.run(SystemThread.java:65)

printed after all logs of my program.

The program exited with exit code 0, so it's not a big issue, but it may be a bit confusing.

The exception should probably be caught somewhere.

I'm not sure how I can repro it consistently but @JaroslavTulach said just the stacktrace will be sufficient for this report.

@JaroslavTulach
Copy link
Member

JaroslavTulach commented Apr 28, 2023

Finalizers are executed asynchronously. In this situation we get a request to finalize something, but there is no longer any Context and Engine to run the finalization. I am afraid we will have to live with such a leak. We do force the finalizers that are pending, but we rely on JVM to tell us to "finalize" - such a request may arrive later, when the Context is already closed. Just like in htis case.

we could force the finalizers ignoring the fact that JVM did not 'yet' tell us

That is an option. But is it a good option? It basically implements Runtime.runFinalizersOnExit and that probably wasn't good idea: https://bugs.openjdk.org/browse/JDK-8198250. There is still Runtime.addShutdownHook - e.g. we could allow Managed_Resource register itself as "shutdown hook" and get a callback when the context is closing.

We can also invoke the "finalizers" when the context is closing too, but only if we have all the "finalizers" under control and we know that they are ready for such a premature (before things are GCed) invocation.

@JaroslavTulach JaroslavTulach added --bug Type: bug and removed triage labels Apr 28, 2023
@JaroslavTulach JaroslavTulach changed the title Exception at end of execution Exception from ResourceManager at end of execution May 2, 2023
@jdunkerley jdunkerley added this to the Beta Release milestone May 2, 2023
@JaroslavTulach
Copy link
Member

JaroslavTulach commented Jul 17, 2023

I tried to reproduce problem in a #7302 test but it seems to be working fine. Does the exception still happen to you, @radeusgd?

I'm not sure how I can repro it consistently but @JaroslavTulach said just the stacktrace will be sufficient for this report.

I did, but I was wrong. The code in Runner & co. seem OKeyish. First of all it joins the Thread, sets isClosed = true and only then continues to GC the pending resources.

@radeusgd
Copy link
Member Author

I tried to reproduce problem in a #7302 test but it seems to be working fine. Does the exception still happen to you, @radeusgd?

I haven't seen it for a while. It was very random to begin with, so it is hard to say. But I guess we can consider it non-reproducible and reopen if we encounter it again?

@mergify mergify bot closed this as completed in #7302 Jul 17, 2023
mergify bot pushed a commit that referenced this issue Jul 17, 2023
…7302)

Demonstration of the ideal behavior of #6472 - the test seems to be working just fine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants