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

Bazel server: ensure file streams are closed #5512

Closed
laszlocsomor opened this issue Jul 4, 2018 · 1 comment
Closed

Bazel server: ensure file streams are closed #5512

laszlocsomor opened this issue Jul 4, 2018 · 1 comment
Assignees
Labels
category: misc > misc P1 I'll work on this now. (Assignee required) type: bug type: process

Comments

@laszlocsomor
Copy link
Contributor

Description of the problem / feature request:

The Bazel server (the Java code) sometimes opens streams without closing them, relying on the garbage collector to finalize the InputStream and close the file. This leads to Bazel holding on to files and (on Windows) being unable to delete them later.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Examples:

protected byte[] getDigest(final Path path, DigestHashFunction hashFunction) throws IOException {
return new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return getInputStream(path);
}
}.hash(hashFunction.getHash()).asBytes();

InputStream in = ctx.getInputPath(this.launcher).getInputStream();

properties.load(sourcePropertiesFilePath.getInputStream());

DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(path.getInputStream());

Correct usage would be try-with-resources:

try (InputStream in = path.getInputStream()) {

What's the output of bazel info release?

release 0.15.0

@laszlocsomor laszlocsomor changed the title Bazel server: ensure InputStreams are closed Bazel server: ensure file streams are closed Jul 4, 2018
@laszlocsomor laszlocsomor self-assigned this Jul 4, 2018
@laszlocsomor laszlocsomor added the P1 I'll work on this now. (Assignee required) label Jul 4, 2018
bazel-io pushed a commit that referenced this issue Jul 5, 2018
Use try-with-resources to ensure InputStreams that
we open via FileSystem.InputStream(path) are
closed.

Eagerly closing InputStreams avoids hanging on to
file handles until the garbage collector finalizes
the InputStream, meaning Bazel on Windows (and
other processes) can delete or mutate these files.

Hopefully this avoids intermittent file deletion
errors that sometimes occur on Windows.

See #5512

RELNOTES: none
PiperOrigin-RevId: 203338148
bazel-io pushed a commit that referenced this issue Jul 5, 2018
Use try-with-resources to ensure OutputStreams
that we open via FileSystem.OutputStream(path)
are closed.

Eagerly closing OutputStreams avoids hanging on to
file handles until the garbage collector finalizes
the OutputStream, meaning Bazel on Windows (and
other processes) can delete or mutate these files.

Hopefully this avoids intermittent file deletion
errors that sometimes occur on Windows.

See #5512

RELNOTES: none
PiperOrigin-RevId: 203342889
bazel-io pushed a commit that referenced this issue Jul 5, 2018
Use the "with" statement to open files in various
Python scripts used by Bazel, to ensure these
files are closed eagerly.

See #5512

RELNOTES: none
PiperOrigin-RevId: 203346678
bazel-io pushed a commit that referenced this issue Jul 9, 2018
Follow-up to commit 59f17d6.

Use try-with-resources to ensure Reader objects
are closed eagerly.

Eagerly closing Readers avoids hanging on to
file handles until the garbage collector finalizes
the object, meaning Bazel on Windows (and
other processes) can delete or mutate these files.

Hopefully this avoids intermittent file deletion
errors that sometimes occur on Windows.

See #5512

RELNOTES: none
PiperOrigin-RevId: 203771262
bazel-io pushed a commit that referenced this issue Jul 10, 2018
Follow-up to commit 09d2031.

Use try-with-resources to ensure Writer objects
are closed eagerly.

Eagerly closing Writers avoids hanging on to
file handles until the garbage collector finalizes
the object, meaning Bazel on Windows (and
other processes) can delete or mutate these files.

Hopefully this avoids intermittent file deletion
errors that sometimes occur on Windows.

See #5512

RELNOTES: none
PiperOrigin-RevId: 203934471
@laszlocsomor
Copy link
Contributor Author

I think this is all fixed now.

werkt pushed a commit to werkt/bazel that referenced this issue Aug 2, 2018
Use try-with-resources to ensure InputStreams that
we open via FileSystem.InputStream(path) are
closed.

Eagerly closing InputStreams avoids hanging on to
file handles until the garbage collector finalizes
the InputStream, meaning Bazel on Windows (and
other processes) can delete or mutate these files.

Hopefully this avoids intermittent file deletion
errors that sometimes occur on Windows.

See bazelbuild#5512

RELNOTES: none
PiperOrigin-RevId: 203338148
werkt pushed a commit to werkt/bazel that referenced this issue Aug 2, 2018
Use try-with-resources to ensure OutputStreams
that we open via FileSystem.OutputStream(path)
are closed.

Eagerly closing OutputStreams avoids hanging on to
file handles until the garbage collector finalizes
the OutputStream, meaning Bazel on Windows (and
other processes) can delete or mutate these files.

Hopefully this avoids intermittent file deletion
errors that sometimes occur on Windows.

See bazelbuild#5512

RELNOTES: none
PiperOrigin-RevId: 203342889
werkt pushed a commit to werkt/bazel that referenced this issue Aug 2, 2018
Use the "with" statement to open files in various
Python scripts used by Bazel, to ensure these
files are closed eagerly.

See bazelbuild#5512

RELNOTES: none
PiperOrigin-RevId: 203346678
werkt pushed a commit to werkt/bazel that referenced this issue Aug 2, 2018
Follow-up to commit 59f17d6.

Use try-with-resources to ensure Reader objects
are closed eagerly.

Eagerly closing Readers avoids hanging on to
file handles until the garbage collector finalizes
the object, meaning Bazel on Windows (and
other processes) can delete or mutate these files.

Hopefully this avoids intermittent file deletion
errors that sometimes occur on Windows.

See bazelbuild#5512

RELNOTES: none
PiperOrigin-RevId: 203771262
werkt pushed a commit to werkt/bazel that referenced this issue Aug 2, 2018
Follow-up to commit 09d2031.

Use try-with-resources to ensure Writer objects
are closed eagerly.

Eagerly closing Writers avoids hanging on to
file handles until the garbage collector finalizes
the object, meaning Bazel on Windows (and
other processes) can delete or mutate these files.

Hopefully this avoids intermittent file deletion
errors that sometimes occur on Windows.

See bazelbuild#5512

RELNOTES: none
PiperOrigin-RevId: 203934471
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    Follow-up to commit 09d20311d982606093ed881d779bb05a5ee70ed3.

    Use try-with-resources to ensure Writer objects
    are closed eagerly.

    Eagerly closing Writers avoids hanging on to
    file handles until the garbage collector finalizes
    the object, meaning Bazel on Windows (and
    other processes) can delete or mutate these files.

    Hopefully this avoids intermittent file deletion
    errors that sometimes occur on Windows.

    See bazelbuild/bazel#5512

    RELNOTES: none
    PiperOrigin-RevId: 203934471
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    Follow-up to commit 59f17d6e0550bf63a0b6ef182e2d63474e058ede.

    Use try-with-resources to ensure Reader objects
    are closed eagerly.

    Eagerly closing Readers avoids hanging on to
    file handles until the garbage collector finalizes
    the object, meaning Bazel on Windows (and
    other processes) can delete or mutate these files.

    Hopefully this avoids intermittent file deletion
    errors that sometimes occur on Windows.

    See bazelbuild/bazel#5512

    RELNOTES: none
    PiperOrigin-RevId: 203771262
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    Use try-with-resources to ensure OutputStreams
    that we open via FileSystem.OutputStream(path)
    are closed.

    Eagerly closing OutputStreams avoids hanging on to
    file handles until the garbage collector finalizes
    the OutputStream, meaning Bazel on Windows (and
    other processes) can delete or mutate these files.

    Hopefully this avoids intermittent file deletion
    errors that sometimes occur on Windows.

    See bazelbuild/bazel#5512

    RELNOTES: none
    PiperOrigin-RevId: 203342889
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    Use try-with-resources to ensure InputStreams that
    we open via FileSystem.InputStream(path) are
    closed.

    Eagerly closing InputStreams avoids hanging on to
    file handles until the garbage collector finalizes
    the InputStream, meaning Bazel on Windows (and
    other processes) can delete or mutate these files.

    Hopefully this avoids intermittent file deletion
    errors that sometimes occur on Windows.

    See bazelbuild/bazel#5512

    RELNOTES: none
    PiperOrigin-RevId: 203338148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: misc > misc P1 I'll work on this now. (Assignee required) type: bug type: process
Projects
None yet
Development

No branches or pull requests

2 participants