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

call close() on compiler in scalacWorker after each job #1504

Merged
merged 2 commits into from
Jul 17, 2023

Conversation

crt-31
Copy link
Contributor

@crt-31 crt-31 commented Jul 11, 2023

Description

This PR fixes the scalacWorker so that it calls close() on the compiler object (nsc.Global) after each job is done. This allows file resources (i.e. dependent jar files, source files, etc) that the compiler uses to be properly released after each job.

Note that nsc.Global did not add the close() functionality until v2.12. This is handled in this PR.

Motivation

This issue was noticed more on Windows since Windows will lock the file (and not allow edits) until it is released. And with scalacWorker being a persistent process, it would lock the files until you called “bazel shutdown”.

This should resolve #1486, where this issue was causing *-ijar.jar handles not to be released.

Aside: There is still an issue where the jars for plugins are not being released (because calling nsc.Global.close() does not release the plugins). This is probably more of a Bazel core issue where Bazel needs to stop the workers when any plugins (or other tooling used by the worker) need to be recompiled. The related issue is Bazel issue #10498.

@crt-31 crt-31 requested review from liucijus and simuons as code owners July 11, 2023 05:43
Copy link
Collaborator

@liucijus liucijus left a comment

Choose a reason for hiding this comment

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

Thanks, @crt-31! Please address style related comments


public class ReportableMainClass extends MainClass {
private Reporter reporter;
private final CompileOptions ops;
private Global _compiler = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: uncommon in Java style to prefix private vars with underscore - please rename to compiler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


public ReportableMainClass(CompileOptions ops) {
this.ops = ops;
}

public void Close() throws Exception{
Copy link
Collaborator

Choose a reason for hiding this comment

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

style nit: don't start method names with a capital letter. Please rename to close()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@liucijus liucijus merged commit 0124872 into bazelbuild:master Jul 17, 2023
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.

ScalacWorker not releasing all file handles after job - causing errors
2 participants