-
Notifications
You must be signed in to change notification settings - Fork 166
Is our handling of open files safe? #436
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
Comments
Just found a tool that might help us to identify what's wrong with This tool can help us to visualize the refcount of nested objects. |
Not exactly what is happening inside the tests. It is quite opposite, the testing environment keeping additional ref counter to the open file handler. This makes StreamWrapper point to a non-deletable object and |
I am closing this issue since I believe it has been fixed. |
Our current strategy is to wrap all file handles in a
StreamWrapper
. It dispatches all calls to wrapped object and adds a__del__
method:It will be called as soon as there are no more references to instance. The rationale is that if this happens we can close the wrapped file object. Since the
StreamWrapper
has a reference to the file object, GC should never try to delete the file object before__del__
of theStreamWrapper
is called. Thus, we should never delete an open file object.Unfortunately, the reasoning above seems not to be correct. In some cases, it seems GC will delete the file object before the
StreamWrapper
is deleted. This will emit a warning which thetorchvision
test suite will turn into an error. This was discussed at length in pytorch/vision#5801 and includes minimum requirements to reproduce the issue. Still, there was no minimal reproduction outside of the test environment found. The issue was presumably fixed in pytorch/pytorch#76345, but was popping up again in https://github.com/pytorch/data/runs/6500848588#step:9:1977.Thus, I think it is valid question to ask if our approach is safe at all. It would be a quite bad UX if a user gets a lot of unclosed file warnings although they used
torchdata
or in extensiontorchvision.datasets
as documented.The text was updated successfully, but these errors were encountered: