libstore: simplify hook instance handling

we never need the connection or the rpc client directly after the hook
is constructed, only the hook instance rpc object. wrapping them using
kj primitives makes this more explicit and prevents destruction errors

Change-Id: I7e0b14d7e365c2e001273e04c0e741ba4afb12f2
This commit is contained in:
eldritch horrors
2025-10-20 12:43:08 +00:00
parent 6c416ff2ca
commit b02a66d13e
3 changed files with 5 additions and 16 deletions
+1 -3
View File
@@ -1055,7 +1055,7 @@ try {
KJ_DEFER(hook = nullptr);
auto output = handleChildOutput();
auto buildReq = hook->rpc.buildRequest();
auto buildReq = hook->rpc->buildRequest();
RPC_FILL(buildReq, setAmWilling, slotToken.valid());
RPC_FILL(buildReq, setNeededSystem, drv->platform);
RPC_FILL(buildReq, initDrvPath, drvPath, worker.store);
@@ -1114,8 +1114,6 @@ try {
// close the rpc connection to have the hook exit
hook->rpc = nullptr;
hook->client = nullptr;
hook->conn = nullptr;
if (auto error = TRY_AWAIT(output)) {
co_return HookResult::Accept{std::move(*error)};
+2 -3
View File
@@ -7,6 +7,7 @@
#include "lix/libutil/rpc.hh"
#include "lix/libutil/strings.hh"
#include "lix/libutil/types-rpc.hh" // IWYU pragma: keep
#include <kj/memory.h>
#include <memory>
namespace nix {
@@ -76,9 +77,7 @@ try {
co_return std::make_unique<HookInstance>(
std::move(fromHook_.readSide),
std::move(conn),
std::move(client),
std::move(rpc),
kj::heap(std::move(rpc)).attach(std::move(conn), std::move(client)),
std::move(pid)
);
} catch (...) {
+2 -10
View File
@@ -19,24 +19,16 @@ struct HookInstance
*/
AutoCloseFD fromHook;
kj::Own<kj::AsyncCapabilityStream> conn;
std::unique_ptr<capnp::TwoPartyClient> client;
rpc::build_remote::HookInstance::Client rpc;
kj::Own<rpc::build_remote::HookInstance::Client> rpc;
std::map<ActivityId, Activity> activities;
static kj::Promise<Result<std::unique_ptr<HookInstance>>> create();
HookInstance(
AutoCloseFD fromHook,
kj::Own<kj::AsyncCapabilityStream> conn,
std::unique_ptr<capnp::TwoPartyClient> client,
rpc::build_remote::HookInstance::Client rpc,
Pid pid
AutoCloseFD fromHook, kj::Own<rpc::build_remote::HookInstance::Client> rpc, Pid pid
)
: fromHook(std::move(fromHook))
, conn(std::move(conn))
, client(std::move(client))
, rpc(std::move(rpc))
, pidOrStatus(std::move(pid))
{