Skip to content

Fix client disconnect when queryPathInfo() returns a negative result#13784

Merged
Mic92 merged 2 commits intomasterfrom
queryPathInfo-dont-disconnect
Aug 19, 2025
Merged

Fix client disconnect when queryPathInfo() returns a negative result#13784
Mic92 merged 2 commits intomasterfrom
queryPathInfo-dont-disconnect

Conversation

@edolstra
Copy link
Member

Motivation

This fixes a bug in RemoteStore::queryPathInfoUncached() where the client disconnects from the daemon if the path is invalid. This is because WorkerProto::BasicClientConnection::queryPathInfo() throws an exception, which causes RemoteStore::ConnectionHandle::~ConnectionHandle() to unnecessarily drop the connection. These disconnects/reconnects can cause big slowdowns for the client.

Since this has the side-effect of fixing negative path info lookup caching for remote stores, we now need to make sure to invalidate path info cache entries in RemoteStore::addToStoreFromDump().

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

…alid paths

This caused RemoteStore::queryPathInfoUncached() to mark the
connection as invalid (see
RemoteStore::ConnectionHandle::~ConnectionHandle()), causing it to
disconnect and reconnect after every lookup of an invalid path. This
caused huge slowdowns in conjunction with
19f89eb and lazy-trees.
@edolstra edolstra requested a review from Ericson2314 as a code owner August 18, 2025 16:39
@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label Aug 18, 2025
try {
std::shared_ptr<const ValidPathInfo> info;
{
auto info = ({
Copy link
Contributor

@xokdvium xokdvium Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this use an immediatelly invoked lambda instead of the GNU extension?

[&](){
  auto conn(getConnection());
  return conn->queryPathInfo(*this, &conn.daemonException, path); 
}();

This is standard C++ at least and not too much worse than the GNU extension.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we're already using statement exprs quite a bit in Nix, and they work fine in both gcc and clang.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, yeah. But I was under the impression that is polyfill from the time before C++ had conveniences for this stuff.

Copy link
Member

@Ericson2314 Ericson2314 Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made lots of the ({...}), and I agree that calling the lambda is better, because I think some rvalue/lvalue stuff is better defined.

(Also, because #9527 someday :))

xokdvium

This comment was marked as outdated.

@xokdvium
Copy link
Contributor

A, nevermind I was looking at the wrong thing.

@xokdvium xokdvium dismissed their stale review August 18, 2025 17:22

Irrelevant

@Mic92 Mic92 merged commit 5c0eff2 into master Aug 19, 2025
29 checks passed
@Mic92 Mic92 deleted the queryPathInfo-dont-disconnect branch August 19, 2025 15:16
@Ericson2314
Copy link
Member

Thanks for fixing my bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants