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

Use TruffleLogger bound to the engine to prevent illegal usage #8169

Merged
merged 5 commits into from
Oct 31, 2023

Conversation

hubertp
Copy link
Collaborator

@hubertp hubertp commented Oct 27, 2023

Pull Request Description

Using a TruffleLogger in SerializationManager that is bound to the engine rather than the context prevents reaching an illegal state when using thread pools.

Also cleaned up some tests for consistency.

To verify the fix

--- a/engine/runtime/src/main/scala/org/enso/compiler/SerializationManager.scala
+++ b/engine/runtime/src/main/scala/org/enso/compiler/SerializationManager.scala
@@ -31,7 +31,7 @@ final class SerializationManager(compiler: Compiler) {
   import SerializationManager._
 
   /** The debug logging level. */
-  private val debugLogLevel = Level.FINE
+  private val debugLogLevel = Level.INFO

and run
sbt:enso> runtime/test

Closes #8147.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.

@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label Oct 27, 2023
@hubertp hubertp marked this pull request as ready for review October 30, 2023 12:01
@hubertp hubertp requested review from 4e6 and Akirathan as code owners October 30, 2023 12:01
private final RuntimeStubsGenerator stubsGenerator;

TruffleCompilerContext(EnsoContext context) {
this.context = context;
this.compiler = context.getLogger(Compiler.class);
this.serializationManager = context.getLogger(SerializationManager.class);
this.compilerLogger = context.getLogger(Compiler.class);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this logger as-is as I haven't seen the same illegal state failures as with SerializationManager, potentially because (de-)serializationis is typically run in a separate thread. We could change it as well, I'm open for suggestions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to bound all loggers to engine. No need to have two getLogger and getLoggerBoundToEngine method.

@hubertp hubertp changed the title Provide log level to prevent truffle logger crash Use TruffleLogger bound to the engine rather than context to prevent illegal usage Oct 30, 2023
@hubertp hubertp changed the title Use TruffleLogger bound to the engine rather than context to prevent illegal usage Use TruffleLogger bound to the engine to prevent illegal usage Oct 30, 2023
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason to have getLogger and getLoggerBoundToEngine next to each other - especially when there is 1:1 mapping between Engine and EnsoContext.

private final RuntimeStubsGenerator stubsGenerator;

TruffleCompilerContext(EnsoContext context) {
this.context = context;
this.compiler = context.getLogger(Compiler.class);
this.serializationManager = context.getLogger(SerializationManager.class);
this.compilerLogger = context.getLogger(Compiler.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to bound all loggers to engine. No need to have two getLogger and getLoggerBoundToEngine method.

Partial fix for Truffle logger crashes - context required log levels.
With a suggested change of log level in `SerializationManager`
`sbt:enso> runtime/testOnly *SerdeCompilerTest`
now passes but
`sbt:enso> runtime/test`
...will continue to fail in `SerdeCompilerTest`, which is really
confusing.
TruffleLoggers bound to the context were problematic when being invoked
in threads coming from a thread pool. By explicitly using a
TruffleLogger that is bound to the engine we can prevent such illegal
usage.
Logs were often sent to null outpu stream or `ByteArrayOutputStream`,
ending up in a black hole. We want to see the logs above the specific
level because they are relevant to debugging problems.
@hubertp hubertp force-pushed the wip/hubert/8147-truffle-logger-crash branch from 9fc5834 to 6bb7a45 Compare October 30, 2023 17:17
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using environment.getLogger(clazz) seems like correct fix.

@hubertp hubertp added the CI: Ready to merge This PR is eligible for automatic merge label Oct 31, 2023
@mergify mergify bot merged commit c1c4c8a into develop Oct 31, 2023
@mergify mergify bot deleted the wip/hubert/8147-truffle-logger-crash branch October 31, 2023 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using TruffleLogger outside of engine leads to crashes
3 participants