scrive / pool

A high-performance striped resource pooling implementation for Haskell
Other
18 stars 11 forks source link

Support for MonadError in construct pool action #28

Closed flip111 closed 1 year ago

flip111 commented 1 year ago

I used the pool together with hasbolt. Pool Pipe is constructed using this function https://hackage.haskell.org/package/hasbolt-0.1.6.2/docs/Database-Bolt.html#v:connect which can throw an error here https://github.com/zmactep/hasbolt/blob/0c233896b59dbb4a7baa18ead3314a8c933472af/src/Database/Bolt/Connection/Pipe.hs#L115

when the error is thrown the withResource function hangs. I guess there was some lazyness somewhere because when i modify the code like this

-- | Striped resource pool based on "Control.Concurrent.QSem".
data Pool a = Pool
  { poolConfig :: !(PoolConfig a)
  , localPools :: !(SmallArray (LocalPool a))
  , reaperRef :: !(IORef ())
  }
instance Show (Pool a) where
  show (Pool {localPools}) = (show localPools)

-- | A single, local pool.
data LocalPool a = LocalPool
  { stripeId :: !Int
  , stripeVar :: !(MVar (Stripe a))
  , cleanerRef :: !(IORef ())
  }
instance Show (LocalPool a) where
  show (LocalPool {stripeId, stripeVar, cleanerRef}) = (show stripeId)

and

takeResource :: Pool a -> IO (a, LocalPool a)
takeResource pool = mask_ $ do
  traceM "takeResource: 1"
  let local_pool = localPools pool
  traceM "takeResource: 2"
  traceM (show local_pool)

the last trace statement never happens and the code hangs on show

flip111 commented 1 year ago

I found out that if connect works successfully then this error still occurs .. must be something else then.

flip111 commented 1 year ago

I'm going to close this as i don't believe any longer there is a problem with resource-pool. Even though i'm still wondering if MonadError is supported. Sorry to bother