perlpilot / p6-File-Temp

Simple implementation of File::Temp for creating temporary files
9 stars 16 forks source link

Tempfile is being unlinked in the middle of a program even if I set :!unlink #18

Open MasterDuke17 opened 8 years ago

MasterDuke17 commented 8 years ago

The Perl 6 version of bisectable writes the code to bisect into a temp file created with File::Temp. However, sometimes during the bisection the temp file gets unlinked (even if I set :!unlink). I've straced the bot and I can see it reading the file for each step of the bisection, and then randomly right in the middle is an unlink, so of course the next bisect steps freak out because the file they've been told to run doesn't exist.

MasterDuke17 commented 8 years ago

So it turns out I was disabling unlinking on the wrong tempfile. Correcting that fixes my program, but the documentation for tempfile is incorrect when it says "Automatically unlink files at end of program (this is the default)". According to https://docs.perl6.org/type/Metamodel$COLON$COLONFinalization#index-entry-DESTROY, "[...] DESTROY submethods are called (if they exist) when an object is garbage-collected."

AlexDaniel commented 7 years ago

This is actually a serious issue.

MasterDuke17 commented 6 years ago

I didn't make it clear in my previous comment. Depending on DESTROY is problematic because there is no requirement for DESTROY to be called during program exit.

https://irclog.perlgeek.de/perl6/2016-09-26#i_13285049 16:11 jnthn jkramer: DESTROY exists, but you have on promises about when it will be called or, if your object lives until close the program exit, if it will be called at all. 16:11 *no promises 16:13 jnthn (To be specific, it gets run shortly after the GC determines the object can be freed.)

https://irclog.perlgeek.de/perl6/2016-03-15#i_12190212 20:08 jnthn MadcapJake`: No, we don't promise to run DESTROY blocks at exit.