Skip to content

Commit

Permalink
Try to rename precomp files multiple times on Windows
Browse files Browse the repository at this point in the history
File renaming can easily race and fail on Windows. There's no great solution,
so instead just try 10 times catching a failure (and returning out of the
loop and method if it succeeds), and if it hasn't succeeded after that, try
one more time without catching a failure.
  • Loading branch information
MasterDuke17 committed Jun 17, 2021
1 parent 4f61a10 commit a9510b8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/core.c/CompUnit/PrecompilationStore/File.pm6
Expand Up @@ -291,6 +291,23 @@ class CompUnit::PrecompilationStore::File
IO::Path:D $path,
Str:D :$extension = ''
) {
if $*DISTRO.is-win {
# File renaming can easily race and fail on Windows. There's no great solution,
# so instead just try 10 times catching a failure (and returning out of the
# loop and method if it succeeds), and if it hasn't succeeded after that, try
# one more time without catching a failure.
my $retry-count = 10;
while $retry-count-- {
$path.rename(self!file($compiler-id, $precomp-id, :$extension));
CATCH {
when X::IO::Rename {
sleep 0.1;
next;
}
}
return;
}
}
$path.rename(self!file($compiler-id, $precomp-id, :$extension));
}

Expand All @@ -301,6 +318,24 @@ class CompUnit::PrecompilationStore::File
) {
my $precomp-file := self!file($compiler-id, $precomp-id, :extension<.tmp>);
$unit.save-to($precomp-file);
if $*DISTRO.is-win {
# File renaming can easily race and fail on Windows. There's no great solution,
# so instead just try 10 times catching a failure (and returning out of the
# loop and method if it succeeds), and if it hasn't succeeded after that, try
# one more time without catching a failure.
my $retry-count = 10;
while $retry-count-- {
$precomp-file.rename(self!file($compiler-id, $precomp-id));
CATCH {
when X::IO::Rename {
sleep 0.1;
next;
}
}
self.remove-from-cache($precomp-id);
return;
}
}
$precomp-file.rename(self!file($compiler-id, $precomp-id));
self.remove-from-cache($precomp-id);
}
Expand All @@ -312,6 +347,23 @@ class CompUnit::PrecompilationStore::File
) {
my $repo-id-file := self!file($compiler-id, $precomp-id, :extension<.repo-id.tmp>);
$repo-id-file.spurt($repo-id);
if $*DISTRO.is-win {
# File renaming can easily race and fail on Windows. There's no great solution,
# so instead just try 10 times catching a failure (and returning out of the
# loop and method if it succeeds), and if it hasn't succeeded after that, try
# one more time without catching a failure.
my $retry-count = 10;
while $retry-count-- {
$repo-id-file.rename(self!file($compiler-id, $precomp-id, :extension<.repo-id>));
CATCH {
when X::IO::Rename {
sleep 0.1;
next;
}
}
return;
}
}
$repo-id-file.rename(self!file($compiler-id, $precomp-id, :extension<.repo-id>));
}

Expand Down
1 change: 1 addition & 0 deletions t/08-performance/05-processkeys.t
Expand Up @@ -6,6 +6,7 @@ my $allowed = (
Q{$AWAITER},
Q{$CWD},
Q{$CORE-SETTING-REV},
Q{$DISTRO},
Q{$ERR},
Q{$IN},
Q{$OUT},
Expand Down

0 comments on commit a9510b8

Please sign in to comment.