From e0936ae38f110db68870b1d80d6c628172d12b4c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 15 Oct 2021 16:12:21 +0200 Subject: [PATCH] Fix crash when a GC client disconnects The client thread can't just delete its own thread object from connections, it has to detach it. --- src/libstore/gc.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index ed792a777..220441927 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -536,7 +536,10 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) auto fdClient_ = fdClient.get(); std::thread clientThread([&, fdClient = std::move(fdClient)]() { Finally cleanup([&]() { - connections.lock()->erase(fdClient.get()); + auto conn(connections.lock()); + auto i = conn->find(fdClient.get()); + i->second.detach(); + conn->erase(i); }); while (true) {