Skip to content

Commit 12184b8

Browse files
committed
Stop running resource freeing functions within uninterruptibleMask
1 parent 1130a72 commit 12184b8

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Use STM based lockless implementation as it results in much better throughput
33
in a multi-threaded environment when number of stripes is not equal to the
44
number of capabilities (in particular with a single stripe).
5+
* Stop running resource freeing functions within `uninterruptibleMask`.
56

67
# resource-pool-0.4.0.0 (2023-01-16)
78
* Require `poolMaxResources` to be not smaller than the number of stripes.

src/Data/Pool/Internal.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,10 @@ cleanStripe isStale free mstripe = mask_ $ do
279279
pure $ map entry stale
280280
-- We need to ignore exceptions in the 'free' function, otherwise if an
281281
-- exception is thrown half-way, we leak the rest of the resources. Also,
282-
-- asynchronous exceptions need to be hard masked here since freeing a
283-
-- resource might in theory block.
284-
uninterruptibleMask_ . forM_ stale $ try @SomeException . free
282+
-- asynchronous exceptions need to be hard masked here we need to run 'free'
283+
-- for all resources.
284+
uninterruptibleMask $ \release -> do
285+
forM_ stale $ try @SomeException . release . free
285286

286287
signal :: forall a. Stripe a -> Maybe a -> STM (Stripe a)
287288
signal stripe ma =

0 commit comments

Comments
 (0)