Skip to content

Commit

Permalink
Fix misread of source if path is already valid
Browse files Browse the repository at this point in the history
When receiving a stream of NARs through the ssh-ng protocol, an already
existing path would cause the NAR archive to not be read in the stream,
resulting in trying to parse the NAR as a ValidPathInfo. This results in
the error message:
    error: not an absolute path: 'nix-archive-1'

Fixes NixOS#6253

Usually this problem is avoided by running QueryValidPaths before
AddMultipleToStore, but can arise when two parallel nix processes gets
the same response from QueryValidPaths. This makes the problem more
prominent when running builds in parallel.
  • Loading branch information
simonrainerson committed Jan 31, 2023
1 parent c9b9260 commit 3e8062c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@
to the embedded store and not to the host's Nix store.

This requires the `discard-references` experimental feature.

* Fix misread of source if path is already valid.
When receiving a stream of NARs through the ssh-ng protocol, an already
existing path would cause the NAR archive to not be read in the stream,
resulting in trying to parse the NAR as a ValidPathInfo. This results in
the error message:
error: not an absolute path: 'nix-archive-1'
17 changes: 17 additions & 0 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,17 @@ void canonicalisePathMetaData(const Path & path,
}


void discardNar(Source& source, const ValidPathInfo& info) {
int count = info.narSize / 4096;
char buffer[4096];
for (int i=0; i < count; ++i) {
source(buffer, 4096);
}
int extra = info.narSize % 4096;
source(buffer, extra);
}


void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivation & drv)
{
assert(drvPath.isDerivation());
Expand Down Expand Up @@ -1343,9 +1354,15 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
optimisePath(realPath, repair); // FIXME: combine with hashPath()

registerValidPath(info);
} else {
/* Discard the NAR from the source if it has been added already. */
discardNar(source, info);
}

outputLock.setDeletion(true);
} else {
/* Discard the NAR from the source if it has been added already. */
discardNar(source, info);
}
}

Expand Down

0 comments on commit 3e8062c

Please sign in to comment.