time-manager 0.1.1 → 0.1.2
raw patch · 3 files changed
+14/−8 lines, 3 files
Files
- ChangeLog.md +5/−0
- System/TimeManager.hs +8/−7
- time-manager.cabal +1/−1
ChangeLog.md view
@@ -1,5 +1,10 @@ # ChangeLog for time-manager +## 0.1.2++* Holding `Weak ThreadId` to prevent thread leak again+ [#1013](https://github.com/yesodweb/wai/pull/1013)+ ## 0.1.1 * Removing `unliftio`.
System/TimeManager.hs view
@@ -28,12 +28,13 @@ TimeoutThread (..), ) where -import Control.Concurrent (myThreadId)+import Control.Concurrent (myThreadId, mkWeakThreadId) import qualified Control.Exception as E import Control.Reaper import Data.IORef (IORef) import qualified Data.IORef as I import Data.Typeable (Typeable)+import GHC.Weak (deRefWeak) ---------------------------------------------------------------- @@ -107,14 +108,14 @@ -- | Registering a timeout action of killing this thread. registerKillThread :: Manager -> TimeoutAction -> IO Handle registerKillThread m onTimeout = do- -- If we hold ThreadId, the stack and data of the thread is leaked.- -- If we hold Weak ThreadId, the stack is released. However, its- -- data is still leaked probably because of a bug of GHC.- -- So, let's just use ThreadId and release ThreadId by- -- overriding the timeout action by "cancel". tid <- myThreadId+ wtid <- mkWeakThreadId tid -- First run the timeout action in case the child thread is masked.- register m $ onTimeout `E.finally` E.throwTo tid TimeoutThread+ register m $ onTimeout `E.finally` do+ mtid <- deRefWeak wtid+ case mtid of+ Nothing -> return ()+ Just tid' -> E.throwTo tid' TimeoutThread data TimeoutThread = TimeoutThread deriving (Typeable)
time-manager.cabal view
@@ -1,5 +1,5 @@ Name: time-manager-Version: 0.1.1+Version: 0.1.2 Synopsis: Scalable timer License: MIT License-file: LICENSE