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

Better error when disposed resources are accessed #243

Open
mcon opened this issue Jan 7, 2022 · 2 comments
Open

Better error when disposed resources are accessed #243

mcon opened this issue Jan 7, 2022 · 2 comments

Comments

@mcon
Copy link

mcon commented Jan 7, 2022

In C# it's pretty easy to accidentally dispose of a resource whilst it's still being used by a task - if you end up reading a file using ParquetSharp after the ParquetFileReader has been disposed then in stead of getting a (more useful) ObjectDisposedException, the library in stead returns incorrect data.

An explicit version of what I ended up doing (yes, looks very silly when made explicit) was:

var file = new ParquetFileReader("myParquetFile");

// Assuming a row group exists
var groupReader = file.RowGroup(0);

file.Dispose()

// Assuming the group has at least one column
groupReader.Column(0); // Throws exception claiming no columns exist

This issue covers having the reader APIs throw ObjectDisposedException to make it clearer to the user how they've misused the library. There's a non-zero chance I might have time to produce a PR for this one.

@mfkl
Copy link
Contributor

mfkl commented Jan 9, 2022

This issue covers having the reader APIs throw ObjectDisposedException to make it clearer to the user how they've misused the library.

Yes, I guess this sounds reasonable. This will break the public API of course. Also this test would need to be changed

[Test]
public static void TestDisposedAccess()
{
    using var buffer = new ResizableBuffer();

    // Write our expected columns to the parquet in-memory file.
    using var outStream = new BufferOutputStream(buffer);
    using var fileWriter = new ParquetFileWriter(outStream, new Column[] {new Column<int>("Index")});

    fileWriter.Dispose();

    var exception = Assert.Throws<NullReferenceException>(() => fileWriter.AppendRowGroup());
    Assert.AreEqual("null native handle", exception?.Message);
}

There's a non-zero chance I might have time to produce a PR for this one.

👍

@GPSnoopy
Copy link
Contributor

GPSnoopy commented Jan 9, 2022

Some of the classes like ColumWriter, ColumnReader, RowGroupWriter and RowGroupReader have now an internal reference to their parent (i.e. creator) instance. AFAIK this was introduced by the LogicalTypeFactory PR.

This should make checking for correct disposal a lot easier, since now the parent instances can have an internal IsDisposed flag that can be checked when these classes are themselves disposed.

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

No branches or pull requests

3 participants