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

Fix non-worker output and also bootstrap scalac nondeterminism #47

Merged
merged 2 commits into from
Jul 26, 2024

Conversation

jjudd
Copy link

@jjudd jjudd commented Jul 26, 2024

Fixes anything that inherits from WorkerMain not writing to the console when not run as a worker.

Fixes a non-determinism bug with bootstrap scalac actions. Check that commit message for a more detailed explanation.

James Judd added 2 commits July 26, 2024 02:00
…e of a sandbox

This fixes a bug where every bootstrap scalac action was writing class
files to the same directory: tmp/classes. Each action would run scalac
with the output directory set to tmp/classes and then create a jar from
all the class files in that directory.

If you're only running a single bootstrap scalac action, then this works
fine.

The bug happens when you run multiple bootstrap scalac actions because
you build up class files in the tmp/classes. This causes the jars you
produce to contain not only the current target's class files, but also
any class files from previous bootstrap scalac actions. Which specific
class files are in your jar depend on what actions have run up until
that point in time. This is not deterministic.

When executing with the sandboxed strategy this bug wasn't an issue
because the sandbox kept actions sufficiently isolated from each other.
Meaning you'd get only your action's classes in the output jar.
// If we do something synchronous with Using, then there's a race condition where the
// streams can get closed before the Future is completed.
var outStream: ByteArrayOutputStream = null
var out: PrintStream = null
Copy link

Choose a reason for hiding this comment

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

Why do these have to be set to null first?

Copy link
Author

Choose a reason for hiding this comment

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

Because if I create the stream here and something goes wrong, then we could leak memory by not closing the stream. By doing so in the future, I'm trying to avoid that. It needs to be declared outside the future, so I can reference it in a subsequent future to be able to close it after the original future has done its work. That's what I'm trying to do with the andThen calls.

@jroylance
Copy link

This looks good to me - that being said I will defer to Gregg's scala expertise 😁

@jjudd
Copy link
Author

jjudd commented Jul 26, 2024

Thanks all for the reviews!

@jjudd jjudd merged commit c8c4345 into lucid-master Jul 26, 2024
1 check passed
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.

3 participants