Skip to content

Conversation

@peterzhu2118
Copy link
Member

As @jeremyevans pointed out:

Each Tempfile instance has a separate File instance and file descriptor:

t = Tempfile.new
t.to_i # => 6
t.dup.to_i => 7

This commit adds the Closer finalizer on dup and clone so that the File object is closed on GC.

As @jeremyevans pointed out:

> Each Tempfile instance has a separate File instance and file descriptor:
>
>   t = Tempfile.new
>   t.to_i # => 6
>   t.dup.to_i => 7

This commit adds the Closer finalizer on dup and clone so that the File
object is closed on GC.
Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

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

I don't think this is correct. This gives every Tempfile dup/clone it's own @finalizer_obj, which will break the Remover, which is only supposed to remove the Tempfile path when all related Tempfile instances have stopped using it. This was handled previously by all dup/clone instances having a reference to the same @finalizer_obj.

See dafabf9 and https://bugs.ruby-lang.org/issues/19441 for the reasons behind the Remover/Closer split.

Maybe to handle Windows, we revert eb2d8b1, and on Windows we have the Remover do nothing (or do not add a finalizer in that case), and the Closer close and then unlink, and just swallow both ENOENT and EACCES for unlink. That should fix the finalizer order issue.

@peterzhu2118
Copy link
Member Author

I took a different approach in #34 that I think fixes all the issues.

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.

3 participants