Skip to content

Conversation

@peterzhu2118
Copy link
Member

The Closer and Remover finalizers are defined on different objects in Tempfile. The Closer is defined on the Tempfile object while the Remover is defined on the finalizer_obj. This means that there is no guarantee of the finalizer order.

On Windows, we must close the file before removing it because we cannot remove an open file. But since the order is not guaranteed, the GC may run the Remover finalizer first, which will fail with an Errno::EACCES (Permission denied @ apply2files).

This commit changes it so that both the Closer and Remover finalizers are defined on the finalizer_obj, which guarantees the order that it is ran.

The Closer and Remover finalizers are defined on different objects in
Tempfile. The Closer is defined on the Tempfile object while the Remover
is defined on the finalizer_obj. This means that there is no guarantee
of the finalizer order.

On Windows, we must close the file before removing it because we cannot
remove an open file. But since the order is not guaranteed, the GC may
run the Remover finalizer first, which will fail with an Errno::EACCES
(Permission denied @ apply2files).

This commit changes it so that both the Closer and Remover finalizers
are defined on the finalizer_obj, which guarantees the order that it is
ran.
olleolleolle added a commit that referenced this pull request Aug 16, 2024
This uses now-compatible "os" choices for Ruby 2.4, 2.5.

This failed in the build of #31.
olleolleolle added a commit that referenced this pull request Aug 16, 2024
This uses now-compatible "os" choices for Ruby 2.5.

This failed in the build of #31.
@peterzhu2118 peterzhu2118 merged commit 37bee10 into master Aug 20, 2024
@peterzhu2118 peterzhu2118 deleted the pz-tempfile-finalizers branch August 20, 2024 13:28
hsbt pushed a commit that referenced this pull request Aug 23, 2024
This uses now-compatible "os" choices for Ruby 2.5.

This failed in the build of #31.
hsbt pushed a commit that referenced this pull request Aug 23, 2024
This uses now-compatible "os" choices for Ruby 2.5.

This failed in the build of #31.
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