From 6dfcb9b09527f8891811192aea0996e7fd7e7c13 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 8 Jul 2026 02:50:26 +0200 Subject: [PATCH] Fix a bug in restoreSize --- CHANGELOG.md | 4 ++++ resource-pool.cabal | 2 +- src/Data/Pool/Internal.hs | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c2e5a..ac857ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# resource-pool-0.5.0.1 (2026-??-??) +* Fix a bug where a thread waiting for a resource would get stuck in the queue + indefinitely if resource creation failed in another thread. + # resource-pool-0.5.0.0 (2025-06-13) * Drop support for GHC < 8.10. * Use STM based lockless implementation as it results in much better throughput diff --git a/resource-pool.cabal b/resource-pool.cabal index 1c6b2ad..3fbfd59 100644 --- a/resource-pool.cabal +++ b/resource-pool.cabal @@ -1,7 +1,7 @@ cabal-version: 3.0 build-type: Simple name: resource-pool -version: 0.5.0.0 +version: 0.5.0.1 license: BSD-3-Clause license-file: LICENSE category: Data, Database, Network diff --git a/src/Data/Pool/Internal.hs b/src/Data/Pool/Internal.hs index a4087cb..21b00d0 100644 --- a/src/Data/Pool/Internal.hs +++ b/src/Data/Pool/Internal.hs @@ -279,7 +279,11 @@ waitForResource mstripe q = atomically (takeTMVar q) `onException` cleanup -- original size of the stripe. restoreSize :: TVar (Stripe a) -> IO () restoreSize mstripe = atomically $ do - modifyTVar' mstripe $ \stripe -> stripe {available = available stripe + 1} + stripe <- readTVar mstripe + -- Signal needs to be called so that if there are threads waiting for a + -- resource, one of them wakes up and attempts the creation itself. + newStripe <- signal stripe Nothing + writeTVar mstripe $! newStripe -- | Free resource entries in the stripes that fulfil a given condition. cleanStripe