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

Make sure that evalaution runs with a proper classloader #473

Merged
merged 1 commit into from
Mar 26, 2021

Conversation

tgodzik
Copy link
Contributor

@tgodzik tgodzik commented Mar 25, 2021

Previously, we would run evalaution with the default mdoc classloader, which might have not contained things like default akka config. Now, we run it in a Thread with the specific classloader set.

Fixes scalameta/metals#2525

@tgodzik tgodzik force-pushed the fix-classloader-issues branch 2 times, most recently from a45a64a to b0880e4 Compare March 25, 2021 16:47
@tgodzik tgodzik requested review from ckipp01 and olafurpg March 25, 2021 16:48
reporter.error(e)
Document.empty(instrumentedInput)
val evaluatedDoc = new AtomicReference[Document]()
val thread = new Thread {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I packed it into a Thread and set the classloader we loaded the DocumentBuilder with. Not sure it's the best way to do it, but seems to work fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suggest using the option to hide whitespace changes,

Copy link
Member

Choose a reason for hiding this comment

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

This is awesome that this is working. Great jump hunting this down. I get the changes, but maybe a silly question, but what class loader what then being used before this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was the one we used for classloading mdoc I think, which didn't have the classes from dependencies.

@tgodzik tgodzik force-pushed the fix-classloader-issues branch from b0880e4 to a5b6d74 Compare March 25, 2021 16:52
Copy link
Member

@ckipp01 ckipp01 left a comment

Choose a reason for hiding this comment

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

Super excited to get this fixed. Again, great job. LGTM!

@tgodzik
Copy link
Contributor Author

tgodzik commented Mar 26, 2021

@olafurpg does this make sense? I am always a bit unsure when it comes to classloaders etc.

Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

I'm not exactly sure why this change fixes the problem. It would be nice (not necessary) if we could at least have a test case to reproduce the original so that we avoid future regression.

Implementation note: it would be nice to wrap the Thread logic into a helper method instead of having it all inline.

I don't think the AtomicReference is necessary, a var should work fine.

@tgodzik
Copy link
Contributor Author

tgodzik commented Mar 26, 2021

I'm not exactly sure why this change fixes the problem. It would be nice (not necessary) if we could at least have a test case to reproduce the original so that we avoid future regression.

That's the Akka test case -> they try to load things from the current classlaoder, which is not the one containing Akka, so it's missing reference.conf resource.

Implementation note: it would be nice to wrap the Thread logic into a helper method instead of having it all inline.

I don't think the AtomicReference is necessary, a var should work fine.

Thanks! Good idea, I will try to improve it.

@tgodzik tgodzik force-pushed the fix-classloader-issues branch from a5b6d74 to f8bee43 Compare March 26, 2021 12:35
Previously, we would run evalaution with the default mdoc classloader, which might have not contained things like default akka config. Now, we run it in a Thread with the specific classloader set.

Fixes scalameta/metals#2525
@tgodzik tgodzik force-pushed the fix-classloader-issues branch from f8bee43 to 5dc9785 Compare March 26, 2021 12:36
@@ -92,6 +97,17 @@ object MarkdownBuilder {
new MarkdownCompiler(fullClasspath.syntax, scalacOptions)
}

private def runInClassLoader(classloader: ClassLoader)(f: () => Unit) = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a separate method for running in a classloader.

"""|import $dep.`com.typesafe.akka::akka-actor:2.6.13`
|import akka.actor.ActorSystem
|
|implicit val system = ActorSystem("worksheet")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I minimized the test case. Creating an actor system should pick up the default reference.conf from the classpath, which doesn't work without the changes.

@tgodzik tgodzik merged commit 2429a02 into scalameta:master Mar 26, 2021
@tgodzik tgodzik deleted the fix-classloader-issues branch March 26, 2021 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scala 3 + Akka streams + worksheet not working
3 participants