on master help sign in
Timeout manager kills threads, does not close sockets
199f8f5Michael Snoyman
Network/Wai/Handler/Warp.hs+1−1
@@ -150,7 +150,7 @@ serveConnections' set app socket = do
150 forever $ do
150 forever $ do
151 (conn, sa) <- accept socket
151 (conn, sa) <- accept socket
152 _ <- forkIO $ do
152 _ <- forkIO $ do
153− th <- T.register tm $ sClose conn
153+ th <- T.registerKillThread tm
154 serveConnection th onE port app conn sa
154 serveConnection th onE port app conn sa
155 T.cancel th
155 T.cancel th
156 return ()
156 return ()
Timeout.hs+7−1
@@ -3,6 +3,7 @@ module Timeout
3 , Handle
3 , Handle
4 , initialize
4 , initialize
5 , register
5 , register
6+ , registerKillThread
6 , tickle
7 , tickle
7 , pause
8 , pause
8 , resume
9 , resume
@@ -10,7 +11,7 @@ module Timeout
10 ) where
11 ) where
11
12
12import qualified Data.IORef as I
13import qualified Data.IORef as I
13−import Control.Concurrent (forkIO, threadDelay)
14+import Control.Concurrent (forkIO, threadDelay, myThreadId, killThread)
14import Control.Monad (forever)
15import Control.Monad (forever)
15import qualified Control.Exception as E
16import qualified Control.Exception as E
16
17
@@ -52,6 +53,11 @@ register (Manager ref) onTimeout = do
52 I.atomicModifyIORef ref (\x -> (h : x, ()))
53 I.atomicModifyIORef ref (\x -> (h : x, ()))
53 return h
54 return h
54
55
56+registerKillThread :: Manager -> IO Handle
57+registerKillThread m = do
58+ tid <- myThreadId
59+ register m $ killThread tid
60+
55tickle, pause, resume, cancel :: Handle -> IO ()
61tickle, pause, resume, cancel :: Handle -> IO ()
56tickle (Handle _ iactive) = I.writeIORef iactive Active
62tickle (Handle _ iactive) = I.writeIORef iactive Active
57pause (Handle _ iactive) = I.writeIORef iactive Paused
63pause (Handle _ iactive) = I.writeIORef iactive Paused
warp.cabal+1−1
@@ -1,5 +1,5 @@
1Name: warp
1Name: warp
2−Version: 0.3.2
2+Version: 0.3.2.1
3Synopsis: A fast, light-weight web server for WAI applications.
3Synopsis: A fast, light-weight web server for WAI applications.
4License: BSD3
4License: BSD3
5License-file: LICENSE
5License-file: LICENSE