From 38dc6f5b69da81dfd21780ef16efaa297f9c2231 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 5 Apr 2024 03:52:51 +0200 Subject: [PATCH] Revert "libutil: drop Pool resources on exceptional free" This reverts commit de2884b82b376d10de5c400d8e73bc7d98f195d2. Change-Id: I1fa301149d7c2ed3d266a40c15b2d010e12e44e6 --- src/libutil/pool.hh | 9 +-------- tests/unit/libutil/pool.cc | 15 --------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/libutil/pool.hh b/src/libutil/pool.hh index b7a749e3a..1cece71ec 100644 --- a/src/libutil/pool.hh +++ b/src/libutil/pool.hh @@ -1,7 +1,6 @@ #pragma once ///@file -#include #include #include #include @@ -119,7 +118,7 @@ public: if (!r) return; { auto state_(pool.state.lock()); - if (!bad && !std::uncaught_exceptions()) + if (!bad) state_->idle.push_back(ref(r)); assert(state_->inUse); state_->inUse--; @@ -135,12 +134,6 @@ public: Handle get() { - // we do not want to handle the complexity that comes with allocating - // resources during stack unwinding. it would be possible to do this, - // but doing so requires more per-handle bookkeeping to properly free - // resources allocated during unwinding. that effort is not worth it. - assert(std::uncaught_exceptions() == 0); - { auto state_(state.lock()); diff --git a/tests/unit/libutil/pool.cc b/tests/unit/libutil/pool.cc index 3ad4ed3aa..90ee509ba 100644 --- a/tests/unit/libutil/pool.cc +++ b/tests/unit/libutil/pool.cc @@ -109,19 +109,4 @@ namespace nix { ASSERT_NE(h->num, counter); } } - - TEST(Pool, throwingOperationDropsResource) - { - auto createResource = []() { return make_ref(); }; - - Pool pool = Pool((size_t)1, createResource); - - ASSERT_THROW({ - auto _r = pool.get(); - ASSERT_EQ(pool.count(), 1); - throw 1; - }, int); - - ASSERT_EQ(pool.count(), 0); - } }