From fa116c96f7a5976cd24ef7cf31844bf662cd2986 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Mon, 16 Jun 2025 18:51:59 +0200 Subject: [PATCH] perl: ensure that stores are destroyed after aio roots otherwise stores containing async objects will cause crashes during shutdown. currently there are no such stores, but that will change. Change-Id: I05d46ba6831c641774edfe6aa99aa7d0de457429 --- perl/lib/Nix/Store.xs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs index 64899e341..094612897 100644 --- a/perl/lib/Nix/Store.xs +++ b/perl/lib/Nix/Store.xs @@ -34,11 +34,15 @@ static AsyncIoRoot & aio() static ref store() { - static std::optional> _store; + auto & aioRoot = aio(); + + // SAFETY: this store will be destructed after its associated aio + // root because the root is initialized first (due to call above) + static thread_local std::optional> _store; if (!_store) { try { initLibStore(); - _store = aio().blockOn(openStore()); + _store = aioRoot.blockOn(openStore()); } catch (Error & e) { croak("%s", e.what()); }