From ca58e97691c9197c1553fb38e30a28b6e7308eef Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 9 Oct 2015 12:50:23 +0200 Subject: [PATCH] Prevent inputs from being garbage collected during evaluation There is still a tiny window between the calls to nix-prefetch-* and addTempRoot. This could be eliminated by adding a "-o" option to nix-prefetch-*, or by not using those scripts at all (and use addToStore directly). --- src/lib/Hydra/Plugin/BazaarInput.pm | 5 +++++ src/lib/Hydra/Plugin/GitInput.pm | 5 +++++ src/lib/Hydra/Plugin/MercurialInput.pm | 5 +++++ src/lib/Hydra/Plugin/SubversionInput.pm | 2 ++ 4 files changed, 17 insertions(+) diff --git a/src/lib/Hydra/Plugin/BazaarInput.pm b/src/lib/Hydra/Plugin/BazaarInput.pm index a896c139..dfd970b6 100644 --- a/src/lib/Hydra/Plugin/BazaarInput.pm +++ b/src/lib/Hydra/Plugin/BazaarInput.pm @@ -36,6 +36,8 @@ sub fetchInput { (my $cachedInput) = $self->{db}->resultset('CachedBazaarInputs')->search( {uri => $uri, revision => $revision}); + addTempRoot($cachedInput->storepath) if defined $cachedInput; + if (defined $cachedInput && isValidPath($cachedInput->storepath)) { $storePath = $cachedInput->storepath; $sha256 = $cachedInput->sha256hash; @@ -53,6 +55,9 @@ sub fetchInput { ($sha256, $storePath) = split ' ', $stdout; + # FIXME: time window between nix-prefetch-bzr and addTempRoot. + addTempRoot($storePath); + txn_do($self->{db}, sub { $self->{db}->resultset('CachedBazaarInputs')->create( { uri => $uri diff --git a/src/lib/Hydra/Plugin/GitInput.pm b/src/lib/Hydra/Plugin/GitInput.pm index 4d75538e..f7322b9d 100644 --- a/src/lib/Hydra/Plugin/GitInput.pm +++ b/src/lib/Hydra/Plugin/GitInput.pm @@ -96,6 +96,8 @@ sub fetchInput { {uri => $uri, branch => $branch, revision => $revision}, {rows => 1}); + addTempRoot($cachedInput->storepath) if defined $cachedInput; + if (defined $cachedInput && isValidPath($cachedInput->storepath)) { $storePath = $cachedInput->storepath; $sha256 = $cachedInput->sha256hash; @@ -124,6 +126,9 @@ sub fetchInput { # FIXME: Don't use nix-prefetch-git. ($sha256, $storePath) = split ' ', grab(cmd => ["nix-prefetch-git", $clonePath, $revision], chomp => 1); + # FIXME: time window between nix-prefetch-git and addTempRoot. + addTempRoot($storePath); + txn_do($self->{db}, sub { $self->{db}->resultset('CachedGitInputs')->update_or_create( { uri => $uri diff --git a/src/lib/Hydra/Plugin/MercurialInput.pm b/src/lib/Hydra/Plugin/MercurialInput.pm index 6882bcce..b6f6c5af 100644 --- a/src/lib/Hydra/Plugin/MercurialInput.pm +++ b/src/lib/Hydra/Plugin/MercurialInput.pm @@ -62,6 +62,8 @@ sub fetchInput { (my $cachedInput) = $self->{db}->resultset('CachedHgInputs')->search( {uri => $uri, branch => $branch, revision => $revision}); + addTempRoot($cachedInput->storepath) if defined $cachedInput; + if (defined $cachedInput && isValidPath($cachedInput->storepath)) { $storePath = $cachedInput->storepath; $sha256 = $cachedInput->sha256hash; @@ -76,6 +78,9 @@ sub fetchInput { ($sha256, $storePath) = split ' ', $stdout; + # FIXME: time window between nix-prefetch-hg and addTempRoot. + addTempRoot($storePath); + txn_do($self->{db}, sub { $self->{db}->resultset('CachedHgInputs')->update_or_create( { uri => $uri diff --git a/src/lib/Hydra/Plugin/SubversionInput.pm b/src/lib/Hydra/Plugin/SubversionInput.pm index 46b479de..db05bb3c 100644 --- a/src/lib/Hydra/Plugin/SubversionInput.pm +++ b/src/lib/Hydra/Plugin/SubversionInput.pm @@ -43,6 +43,8 @@ sub fetchInput { (my $cachedInput) = $self->{db}->resultset('CachedSubversionInputs')->search( {uri => $uri, revision => $revision}); + addTempRoot($cachedInput->storepath) if defined $cachedInput; + if (defined $cachedInput && isValidPath($cachedInput->storepath)) { $storePath = $cachedInput->storepath; $sha256 = $cachedInput->sha256hash;