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

Temporary file created by HybridMemoryStream in Transposer not deleted #367

Closed
mjmckp opened this issue Jun 17, 2018 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@mjmckp
Copy link

mjmckp commented Jun 17, 2018

The HybridMemoryStream created in the Transposer

var stream = new HybridMemoryStream();

is closed, but never disposed. This is because the Dispose implementation of the BinaryLoader here

only calls Dispose on the System.IO.BinaryReader it contains, which in turn only calls Close on HybridMemoryStream, but not Dispose (see https://referencesource.microsoft.com/#mscorlib/system/io/binaryreader.cs,91). Therefore, the deletion of the temporary file here

is never reached.

This is causing the temporary directory on my PC to fill up all the available space on the disk.

@shauheen shauheen added the bug Something isn't working label Jun 18, 2018
@TomFinley
Copy link
Contributor

TomFinley commented Jun 18, 2018

D'oh, thanks for finding this @mjmckp . :( I'm rather surprised that the System.IO.BinaryReader dispose does not call dispose on the stream. My expectation, which may be wrong, is that if something implements IDisposable that any objects it "owns" that are also IDisposable should be likewise disposed. But, possibly my expectations are incorrect.

Generally from what I read here:
https://github.com/dotnet/corefx/blob/55f2293ddda3c972fcc2d94915b03bc8556e8c9b/src/Common/src/CoreLib/System/IO/Stream.cs#L211-L223
I think the idea is that Stream.Close overrides should call base.Close, and I notice that we're not doing that here and in one other case. If we do that perhaps that will resolve the issue.

@glebuk
Copy link
Contributor

glebuk commented Jun 18, 2018

I suggest we use belt and suspenders approach. Even with proper Dispose() code, if the process is killed due to timeout, error, or user action, the file will remain. There exists a DeleteOnClose option that instructs the OS to delete this file even in the process is suddenly killed without disposers running their course.

Suggest we update the IFileHandle.cs to do something like this:

if (_autoDelete)
    _streamWrite = new FileStream(_fullPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, 4096, FileOptions.DeleteOnClose);

@ghost ghost locked as resolved and limited conversation to collaborators Mar 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants