http://qs321.pair.com?node_id=1230174


in reply to Intermittent bug in module: File not getting deleted as expected

Could your test be failing due to a timing issue, here, due to this param?

It doesn't really look like it because it does appear as though you're handling and sending in the $age param correctly, but printing out the variables wouldn't hurt (ie. my $x = -M $file; print "$x: $age\n";) to see what's going on there for real.

Can you reproduce it on a local machine at all?

You could try adding a delay of a second after the cleanup() routine (eg: sleep 1;), and before the file-exists test. Perhaps the full cleanup of the file isn't quite complete in some systems before checking if the file is really gone.

Replies are listed 'Best First'.
Re^2: Intermittent bug in module: File not getting deleted as expected
by nysus (Parson) on Feb 19, 2019 at 18:28 UTC

    So, I found the issue, but not the solution. When the test fails, -M $file is a negative value like -1.15740740740741e-05.

    I can reproduce on a local machine, yes. It happens maybe 10% of the time, which is weird. I had tried adding a delay already. I just tried increasing the delay to a full 2 seconds and that didn't help.

    When the test fails, I do see the file pop up momentarily in the directory. So it definitely exists (and the previous test proves it).

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      By the way, the time value appears to always be the same: -1.15740740740741e-05

      Interestingly, that appears to be exactly 1 second. But why is it negative?

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        That, I'm unsure of. From perldoc -f -X:

        -M Script start time minus file modification time, in days.

        Does File::Spec->catfile() modify the file mod time by chance? What happens if you put a two second delay in between that line (in the lib), and the unlink() call? Does that improve things? I know that's definitely not optimal, but it would be worth a shot especially if you can reliably reproduce the issue locally.