-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing unliftio #1012
Removing unliftio #1012
Changes from all commits
c68dc99
0acc630
155ad18
65c9669
17ddfcc
e991c3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,19 @@ module Network.Wai.Handler.WarpTLS ( | |
) where | ||
|
||
import Control.Applicative ((<|>)) | ||
import Control.Exception ( | ||
Exception, | ||
IOException, | ||
SomeException (..), | ||
bracket, | ||
finally, | ||
fromException, | ||
handle, | ||
handleJust, | ||
onException, | ||
throwIO, | ||
try, | ||
) | ||
import Control.Monad (guard, void) | ||
import qualified Data.ByteString as S | ||
import qualified Data.ByteString.Lazy as L | ||
|
@@ -73,6 +86,7 @@ import Network.Socket ( | |
#endif | ||
withSocketsDo, | ||
) | ||
import qualified Control.Exception as E | ||
import Network.Socket.BufferPool | ||
import Network.Socket.ByteString (sendAll) | ||
import qualified Network.TLS as TLS | ||
|
@@ -82,23 +96,7 @@ import Network.Wai.Handler.Warp | |
import Network.Wai.Handler.Warp.Internal | ||
import Network.Wai.Handler.WarpTLS.Internal | ||
import System.IO.Error (ioeGetErrorType, isEOFError) | ||
import UnliftIO.Exception ( | ||
Exception, | ||
IOException, | ||
SomeException (..), | ||
bracket, | ||
finally, | ||
fromException, | ||
handle, | ||
handleAny, | ||
handleJust, | ||
onException, | ||
throwIO, | ||
try, | ||
) | ||
import qualified UnliftIO.Exception as E | ||
import UnliftIO.Concurrent (newEmptyMVar, putMVar, takeMVar, forkIOWithUnmask) | ||
import UnliftIO.Timeout (timeout) | ||
import System.Timeout (timeout) | ||
|
||
---------------------------------------------------------------- | ||
|
||
|
@@ -323,12 +321,8 @@ mkConn | |
-> params | ||
-> IO (Connection, Transport) | ||
mkConn tlsset set s params = do | ||
var <- newEmptyMVar | ||
_ <- forkIOWithUnmask $ \umask -> do | ||
let tm = settingsTimeout set * 1000000 | ||
mct <- umask (timeout tm recvFirstBS) | ||
putMVar var mct | ||
mbs <- takeMVar var | ||
let tm = settingsTimeout set * 1000000 | ||
mbs <- timeout tm recvFirstBS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this makes sense, but if we want to keep the same behaviour we'd have to change it to: mbs <- unsafeUnmask $ timeout tm recvFirstBS There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original code before unsafeUnmask does not have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Because the whole So no, I have changed my stance and adding |
||
case mbs of | ||
Nothing -> throwIO IncompleteHeaders | ||
Just bs -> switch bs | ||
|
@@ -366,7 +360,7 @@ httpOverTls TLSSettings{..} set s bs0 params = | |
case mconn of | ||
Nothing -> throwIO IncompleteHeaders | ||
Just conn -> return conn | ||
wrappedRecvN recvN n = handleAny (const mempty) $ recvN n | ||
wrappedRecvN recvN n = handle (\(SomeException _) -> mempty) $ recvN n | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this will now also catch (and ignore) async exceptions. |
||
backend recvN = | ||
TLS.Backend | ||
{ TLS.backendFlush = return () | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,7 @@ module Network.Wai.Handler.Warp ( | |
|
||
import Data.Streaming.Network (HostPreference) | ||
import qualified Data.Vault.Lazy as Vault | ||
import UnliftIO.Exception (SomeException, throwIO) | ||
import Control.Exception (SomeException, throwIO) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
#ifdef MIN_VERSION_crypton_x509 | ||
import Data.X509 | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
|
||
module Network.Wai.Handler.Warp.Conduit where | ||
|
||
import Control.Exception (assert, throwIO) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
import qualified Data.ByteString as S | ||
import qualified Data.IORef as I | ||
import Data.Word8 (_0, _9, _A, _F, _a, _cr, _f, _lf) | ||
import UnliftIO (assert, throwIO) | ||
|
||
import Network.Wai.Handler.Warp.Imports | ||
import Network.Wai.Handler.Warp.Types | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ import System.Posix.IO ( | |
openFd, | ||
setFdOption, | ||
) | ||
import UnliftIO.Exception (bracket) | ||
import Control.Exception (bracket) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resouce-release actions in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes. Never mind. I've re-read the |
||
#endif | ||
import System.Posix.Types (Fd) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,14 @@ module Network.Wai.Handler.Warp.FileInfoCache ( | |
getInfo, -- test purpose only | ||
) where | ||
|
||
import Control.Exception (bracket, onException, throwIO) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
import Control.Reaper | ||
import Network.HTTP.Date | ||
#if WINDOWS | ||
import System.PosixCompat.Files | ||
#else | ||
import System.Posix.Files | ||
#endif | ||
import qualified UnliftIO (bracket, onException, throwIO) | ||
|
||
import Network.Wai.Handler.Warp.HashMap (HashMap) | ||
import qualified Network.Wai.Handler.Warp.HashMap as M | ||
|
@@ -58,7 +58,7 @@ getInfo path = do | |
, fileInfoDate = date | ||
} | ||
return info | ||
else UnliftIO.throwIO (userError "FileInfoCache:getInfo") | ||
else throwIO (userError "FileInfoCache:getInfo") | ||
|
||
getInfoNaive :: FilePath -> IO FileInfo | ||
getInfoNaive = getInfo | ||
|
@@ -69,11 +69,11 @@ getAndRegisterInfo :: FileInfoCache -> FilePath -> IO FileInfo | |
getAndRegisterInfo reaper path = do | ||
cache <- reaperRead reaper | ||
case M.lookup path cache of | ||
Just Negative -> UnliftIO.throwIO (userError "FileInfoCache:getAndRegisterInfo") | ||
Just Negative -> throwIO (userError "FileInfoCache:getAndRegisterInfo") | ||
Just (Positive x) -> return x | ||
Nothing -> | ||
positive reaper path | ||
`UnliftIO.onException` negative reaper path | ||
`onException` negative reaper path | ||
|
||
positive :: FileInfoCache -> FilePath -> IO FileInfo | ||
positive reaper path = do | ||
|
@@ -84,7 +84,7 @@ positive reaper path = do | |
negative :: FileInfoCache -> FilePath -> IO FileInfo | ||
negative reaper path = do | ||
reaperAdd reaper (path, Negative) | ||
UnliftIO.throwIO (userError "FileInfoCache:negative") | ||
throwIO (userError "FileInfoCache:negative") | ||
|
||
---------------------------------------------------------------- | ||
|
||
|
@@ -97,7 +97,7 @@ withFileInfoCache | |
-> IO a | ||
withFileInfoCache 0 action = action getInfoNaive | ||
withFileInfoCache duration action = | ||
UnliftIO.bracket | ||
bracket | ||
(initialize duration) | ||
terminate | ||
(action . getAndRegisterInfo) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main change because of this would be that
AsyncException
s will also be ignored if they are thrown duringtimeoutAction
(whereas they wouldn't before)So (I think?) this means a thread might be failed to be killed if the async exception is thrown while the
timeoutAction
is running?So we might want to change to
safe-exceptions
instead ofunliftio
?