ruby / tempfile

A utility class for managing temporary files.
Other
29 stars 10 forks source link

Ensure finalizer order in Tempfile #31

Closed peterzhu2118 closed 3 weeks ago

peterzhu2118 commented 3 weeks ago

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.