@@ -123,26 +123,10 @@ runSettingsConnectionMakerSecure :: Settings -> IO (IO (Connection, Bool), SockA
123123runSettingsConnectionMakerSecure set getConnMaker app = do
124124 settingsBeforeMainLoop set
125125
126− -- Note that there is a thorough discussion of the exception safety of the
127− -- following code at: https://github.com/yesodweb/wai/issues/146
128− --
129− -- We need to make sure of two things:
130− --
131− -- 1. Asynchronous exceptions are not blocked entirely in the main loop.
132− -- Doing so would make it impossible to kill the Warp thread.
133− --
134− -- 2. Once a connection maker is received via getConnLoop, the connection
135− -- is guaranteed to be closed, even in the presence of async exceptions.
136− --
137− -- Our approach is explained in the comments below.
138−
139− -- First mask all exceptions in the main loop. This is necessary to ensure
140− -- that no async exception is throw between the call to getConnLoop and the
141− -- registering of connClose.
142126 D.withDateCache $ \dc ->
143127 F.withFdCache fdCacheDurationInSeconds $ \fc ->
144128 withTimeoutManager $ \tm ->
145− mask_ $ acceptConnection set getConnMaker app dc fc tm
129+ acceptConnection set getConnMaker app dc fc tm
146130 where
147131 fdCacheDurationInSeconds = settingsFdCacheDuration set * 1000000
148132 withTimeoutManager f =
@@ -153,6 +137,18 @@ runSettingsConnectionMakerSecure set getConnMaker app = do
153137 f
154138 Just tm -> f tm
155139
140+-- Note that there is a thorough discussion of the exception safety of the
141+-- following code at: https://github.com/yesodweb/wai/issues/146
142+--
143+-- We need to make sure of two things:
144+--
145+-- 1. Asynchronous exceptions are not blocked entirely in the main loop.
146+-- Doing so would make it impossible to kill the Warp thread.
147+--
148+-- 2. Once a connection maker is received via getConnLoop, the connection
149+-- is guaranteed to be closed, even in the presence of async exceptions.
150+--
151+-- Our approach is explained in the comments below.
156152acceptConnection :: Settings
157153 -> IO (IO (Connection, Bool), SockAddr)
158154 -> Application
@@ -160,7 +156,10 @@ acceptConnection :: Settings
160156 -> Maybe F.MutableFdCache
161157 -> T.Manager
162158 -> IO ()
163−acceptConnection set getConnMaker app dc fc tm = do
159+-- First mask all exceptions in the main loop. This is necessary to ensure
160+-- that no async exception is throw between the call to getConnLoop and the
161+-- registering of connClose.
162+acceptConnection set getConnMaker app dc fc tm = mask_ $ do
164163 -- Allow async exceptions before receiving the next connection maker.
165164 allowInterrupt
166165