http-conduit 1.9.4.2 → 1.9.4.3
raw patch · 2 files changed
+20/−9 lines, 2 files
Files
- Network/HTTP/Conduit/Manager.hs +19/−8
- http-conduit.cabal +1/−1
Network/HTTP/Conduit/Manager.hs view
@@ -21,6 +21,7 @@ , failedConnectionException ) where +import Debug.Trace #if !MIN_VERSION_base(4,6,0) import Prelude hiding (catch) #endif@@ -65,7 +66,7 @@ import Data.Default import Data.Maybe (mapMaybe) import System.IO (Handle)-import System.Mem.Weak (addFinalizer)+import System.Mem.Weak (Weak, deRefWeak) import Data.Conduit (($$), yield, runException) -- | Settings for a @Manager@. Please use the 'def' function and then modify@@ -138,7 +139,7 @@ takeSocket man key = I.atomicModifyIORef (mConns man) go where- go Nothing = (Nothing, Nothing)+ go Nothing = trace "Using a closed manager" (Nothing, Nothing) go (Just m) = case Map.lookup key m of Nothing -> (Just m, Nothing)@@ -184,8 +185,9 @@ return certStore Just x -> return x mapRef <- I.newIORef (Just Map.empty)+ wmapRef <- I.mkWeakIORef mapRef $ closeManager' mapRef certCache <- I.newIORef Map.empty- _ <- forkIO $ reap mapRef certCache+ _ <- forkIO $ reap wmapRef certCache let manager = Manager { mConns = mapRef , mMaxConns = managerConnCount ms@@ -193,18 +195,23 @@ , mCertCache = certCache , mResponseTimeout = managerResponseTimeout ms }- addFinalizer manager $ closeManager manager return manager -- | Collect and destroy any stale connections.-reap :: I.IORef (Maybe (Map.Map ConnKey (NonEmptyList ConnInfo)))+reap :: Weak (I.IORef (Maybe (Map.Map ConnKey (NonEmptyList ConnInfo)))) -> I.IORef (Map.Map S8.ByteString (Map.Map X509Encoded UTCTime)) -> IO ()-reap mapRef certCacheRef =+reap wmapRef certCacheRef = mask_ loop where loop = do threadDelay (5 * 1000 * 1000)+ mmapRef <- deRefWeak wmapRef+ case mmapRef of+ Nothing -> return () -- manager is closed+ Just mapRef -> goMapRef mapRef++ goMapRef mapRef = do now <- getCurrentTime let isNotStale time = 30 `addUTCTime` time >= now mtoDestroy <- I.atomicModifyIORef mapRef (findStaleWrap isNotStale)@@ -313,8 +320,12 @@ -- meaning you can safely use it without hurting any queries you may -- have concurrently running. closeManager :: Manager -> IO ()-closeManager manager = mask_ $ do- m <- I.atomicModifyIORef (mConns manager) $ \x -> (Nothing, x)+closeManager = closeManager' . mConns++closeManager' :: I.IORef (Maybe (Map.Map ConnKey (NonEmptyList ConnInfo)))+ -> IO ()+closeManager' connsRef = mask_ $ do+ m <- I.atomicModifyIORef connsRef $ \x -> (Nothing, x) mapM_ (nonEmptyMapM_ safeConnClose) $ maybe [] Map.elems m safeConnClose :: ConnInfo -> IO ()
http-conduit.cabal view
@@ -1,5 +1,5 @@ name: http-conduit-version: 1.9.4.2+version: 1.9.4.3 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>