If you fork multiple children, and tee in them, the tmpfile names can get reused in the children, which causes tee to wait on files cleaned up by other processes. I believe what's happening is that the same random number seed is being used in the child procs, which makes tmpnam return identical file names.
Below is an example which triggers this case.
#!/usr/bin/env perl
use strict;
use warnings;
use Capture::Tiny qw(tee);
use POSIX qw();
my $random = rand(); # something to set the rng seed
my @pids;
my $children = 2;
for (1 .. $children) {
if (my $pid = fork) {
push @pids, $pid;
} else {
# uncommenting will stop it from hanging
# srand();
tee { 42 };
POSIX::_exit(0);
}
}
waitpid($_, 0) for @pids;
I was able to work around the issue by calling srand in the children, but I believe this could be safely fixed inside Capture::Tiny if the tmp files included pids in the name. This would guarantee uniqueness across children.
If you fork multiple children, and tee in them, the tmpfile names can get reused in the children, which causes tee to wait on files cleaned up by other processes. I believe what's happening is that the same random number seed is being used in the child procs, which makes
tmpnam
return identical file names.Below is an example which triggers this case.
I was able to work around the issue by calling
srand
in the children, but I believe this could be safely fixed inside Capture::Tiny if the tmp files included pids in the name. This would guarantee uniqueness across children.