bos / pool

A high-performance striped resource pooling implementation for Haskell
Other
112 stars 59 forks source link

Finalizer being called early on `fin` `IORef` #28

Open lunaris opened 8 years ago

lunaris commented 8 years ago

When using pool to manage a series of PostgreSQL connections (via postgresql-simple), I've found that idle connections are not being reaped. After doing some digging, it appears that the reaper thread is being killed almost immediately, which I've linked to the execution of the finaliser attached to the internal fin IORef. I've no doubt that this is an issue with my code and not pool, but was wondering if I might find some help here. While I've not managed to produce a minimal reproducing test case, I have details about what I'm doing:

MyPool <$>
  createPool PG.createConnection PG.closeConnection noOfStripes maxIdleTime perStripe
createPostgreSQLConnectionPool
  :: PostgreSQLConfiguration
     -> PostgreSQLConnectionPoolConfiguration
     -> IO PostgreSQLConnectionPool
[GblId, Arity=2, Str=DmdType]
createPostgreSQLConnectionPool =
  \ (ds_doFL :: PostgreSQLConfiguration)
    (ds1_doFM :: PostgreSQLConnectionPoolConfiguration) ->
    case ds_doFL
    of _ [Occ=Dead]
    { PostgreSQLConfiguration ds2_doFN ds3_doFO ds4_doFP ds5_doFQ
                              ds6_doFR ->
    case ds1_doFM
    of _ [Occ=Dead]
    { PostgreSQLConnectionPoolConfiguration ds7_doFS ds8_doFT
                                            ds9_doFU ->
    let {
      closePostgreSQL_anEf :: PG.Connection -> IO ()
      [LclId, Str=DmdType]
      closePostgreSQL_anEf =
        \ (conn_anEg :: PG.Connection) ->
          >>
            @ IO
            GHC.Base.$fMonadIO
            @ ()
            @ ()
            (putStrLn
               (ghc-prim-0.4.0.0:GHC.CString.unpackCString#
                  "[PG] Closing connection"#))
            (PG.close conn_anEg) } in
    let {
      connectToPostgreSQL'_anEe :: IO PG.Connection
      [LclId, Str=DmdType]
      connectToPostgreSQL'_anEe =
        >>
          @ IO
          GHC.Base.$fMonadIO
          @ ()
          @ PG.Connection
          (putStrLn
             (ghc-prim-0.4.0.0:GHC.CString.unpackCString#
                "[PG] Creating connection"#))
          (PG.connect
             (case PG.defaultConnectInfo
              of _ [Occ=Dead]
              { PG.ConnectInfo ds10_doG0 ds11_doG1 ds12_doG2 ds13_doG3
                               ds14_doG4 ->
              Database.PostgreSQL.Simple.Internal.ConnectInfo
                ds2_doFN
                (fromIntegral
                   @ Int
                   @ GHC.Word.Word16
                   GHC.Real.$fIntegralInt
                   GHC.Word.$fNumWord16
                   ds3_doFO)
                ds4_doFP
                ds5_doFQ
                ds6_doFR
              })) } in
    <$>
      @ (Pool.Pool PG.Connection)
      @ PostgreSQLConnectionPool
      @ IO
      GHC.Base.$fFunctorIO
      ((\ (tpl_B1 :: Pool.Pool PG.Connection) -> tpl_B1)
       `cast` (<Pool.Pool PG.Connection>_R
               -> Sym
                    Company.PostgreSQL.Internal.Trans.NTCo:PostgreSQLConnectionPool[0]
               :: (Pool.Pool PG.Connection -> Pool.Pool PG.Connection)
                  ~R# (Pool.Pool PG.Connection -> PostgreSQLConnectionPool)))
      (Pool.createPool
         @ PG.Connection
         connectToPostgreSQL'_anEe
         closePostgreSQL_anEf
         ds7_doFS
         (fromIntegral
            @ Int
            @ time-1.5.0.1:Data.Time.Clock.UTC.NominalDiffTime
            GHC.Real.$fIntegralInt
            time-1.5.0.1:Data.Time.Clock.UTC.$fNumNominalDiffTime
            ds8_doFT)
         ds9_doFU)
    }
    }

Thanks in advance for any advice and apologies for not providing a minimal working example; I am struggling to find out exactly what I'm doing that's causing this. If there is any other information I can provide in the mean time I am happy to oblige to try and crack this.