@@ -5,6 +5,7 @@ module Network.Wai.Handler.Warp.Run where
55
66import Control.Concurrent (threadDelay, forkIOWithUnmask)
77import Control.Exception
8+import qualified Control.Exception.Lifted as Lifted
89import Control.Monad (forever, when, unless, void)
910import Control.Monad.IO.Class (MonadIO, liftIO)
1011import qualified Control.Monad.Trans.Resource as Res
@@ -200,7 +201,7 @@ runSettingsConnectionMaker set getConn app = do
200201 in unmask .
201202 -- Call the user-supplied on exception code if any
202203 -- exceptions are thrown.
203− handle onE .
204+ handle (onE Nothing) .
204205
205206 -- Call the user-supplied code for connection open and close events
206207 bracket_ onOpen onClose $
@@ -210,7 +211,7 @@ runSettingsConnectionMaker set getConn app = do
210211 where
211212 -- FIXME: only IOEception is caught. What about other exceptions?
212213 getConnLoop = getConn `catch` \(e :: IOException) -> do
213− onE (toException e)
214+ onE Nothing (toException e)
214215 -- "resource exhausted (Too many open files)" may happen by accept().
215216 -- Wait a second hoping that resource will be available.
216217 threadDelay 1000000
@@ -241,9 +242,11 @@ serveConnection timeoutHandle settings cleaner app conn remoteHost' =
241242 | otherwise = f env
242243 th = threadHandle cleaner
243244
245+ onE env = liftIO . settingsOnException settings env
246+
244247 serveConnection'' fromClient internalState = do
245248 (env, getSource) <- parseRequest conn timeoutHandle internalState remoteHost' fromClient
246− case settingsIntercept settings env of
249+ Lifted.handle (onE (Just env)) $ case settingsIntercept settings env of
247250 Nothing -> do
248251 -- Let the application run for as long as it wants
249252 liftIO $ T.pause th