Skip to content

Commit 6185d25

Browse files
committed
Make 'nix copy --to daemon' run in constant memory (daemon side)
Continuation of 97002b6. This makes the daemon use constant memory. For example, it reduces the daemon's maximum RSS on $ nix copy --from ~/my-nix --to daemon /nix/store/1n7x0yv8vq6zi90hfmian84vdhd04bgp-blender-2.79a from 264 MiB to 7 MiB. We now use a TunnelSource to prevent the connection from ending up in an undefined state if an exception is thrown while the NAR is being sent. Issue #1681.
1 parent 23d6bb5 commit 6185d25

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/libstore/remote-store.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,9 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
411411
<< info.references << info.registrationTime << info.narSize
412412
<< info.ultimate << info.sigs << info.ca
413413
<< repair << !checkSigs;
414-
copyNAR(source, conn->to);
415-
conn->processStderr();
414+
bool tunnel = GET_PROTOCOL_MINOR(conn->daemonVersion) >= 21;
415+
if (!tunnel) copyNAR(source, conn->to);
416+
conn->processStderr(0, tunnel ? &source : nullptr);
416417
}
417418
}
418419

src/libstore/worker-protocol.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace nix {
66
#define WORKER_MAGIC_1 0x6e697863
77
#define WORKER_MAGIC_2 0x6478696f
88

9-
#define PROTOCOL_VERSION 0x114
9+
#define PROTOCOL_VERSION 0x115
1010
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
1111
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
1212

src/nix-daemon/nix-daemon.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,22 @@ static void performOp(TunnelLogger * logger, ref<LocalStore> store,
690690
if (!trusted)
691691
info.ultimate = false;
692692

693-
TeeSink tee(from);
694-
parseDump(tee, tee.source);
693+
std::string saved;
694+
std::unique_ptr<Source> source;
695+
if (GET_PROTOCOL_MINOR(clientVersion) >= 21)
696+
source = std::make_unique<TunnelSource>(from);
697+
else {
698+
TeeSink tee(from);
699+
parseDump(tee, tee.source);
700+
saved = std::move(*tee.source.data);
701+
source = std::make_unique<StringSource>(saved);
702+
}
695703

696704
logger->startWork();
697-
store.cast<Store>()->addToStore(info, tee.source.data, (RepairFlag) repair,
705+
706+
store.cast<Store>()->addToStore(info, *source, (RepairFlag) repair,
698707
dontCheckSigs ? NoCheckSigs : CheckSigs, nullptr);
708+
699709
logger->stopWork();
700710
break;
701711
}

0 commit comments

Comments
 (0)