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

Ensure finalizer order in Tempfile #31

Merged
merged 1 commit into from
Aug 20, 2024
Merged

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
6 of 50 checks passed
@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
Development

Successfully merging this pull request may close these issues.

2 participants