-
Notifications
You must be signed in to change notification settings - Fork 193
Description
After having my laptop die and I got a new one, I loaded up some code that use to work, installed a sandbox and started running into some problems. Pretty much every request was giving me a TimeoutTriggered
exception. When I tested even a simple GET request on http://google.com was giving me a TimeoutTriggered
.
So I went through a lot of things to see what the cause was:
- I had been using
Network.HTTP.Client.Conduit
because it added a bunch of features by default that I had done manually (the MonadReader for the Manager was a great touch). So I changed that back toNetwork.HTTP.Conduit
. Result was the same. - I noticed the problem was in
http-client
so I tried going back 2 or 3 versions but that didn't seem to make a difference. Went back all the way to 0.4.7.2 - I've been using GHC 7.10.1 and I thought maybe something there was causing the issue. So I dropped back to GHC 7.8.4 and I kept having the problem.
So finally I went through my old hard drive and looked in the sandbox to see what version of http-client I had installed. Turns out it was 0.4.7.1 (if only I had tried going back one more version...). It's upload date is Feb 2nd, which was then followed by this commit on Feb 10: 19edc22
After that, it must have made it into 0.4.7.2.
Having reverted to 0.4.7.1 everything works as it did before.
FYI I'm on Windows and if it helps the module that makes the connection is written like this:
httpConnection ::
(MonadCatch m, MonadWriter EventLog m, MonadIO m, HasHttpManager h, MonadReader h m)
=> Connection -> m B.ByteString
httpConnection (GET url) = targetURL url [] id
httpConnection (POST url argshead argsbody) = targetURL url postLogs updateRequest
where
postLogs = ["With header arguments: " ++ show argshead, "With body args:" ++ show argsbody]
argsheadFormatted :: [Header]
argsheadFormatted = map (first CI.mk) argshead
updateRequest initReq = if null argsbody then postReq else urlEncodedBody argsbody postReq
where
postReq = initReq { requestHeaders = requestHeaders initReq ++ argsheadFormatted, method = C.pack "POST" }
targetURL ::
(MonadCatch m, MonadWriter EventLog m, MonadIO m, HasHttpManager h, MonadReader h m)
=> String -> [String] -> (Request -> Request) -> m B.ByteString
targetURL url ls g = do
timeLog $ "Attempting to connect to URL: " ++ url
unless (null ls) $ mapM_ timeLog ls
mgr <- asks getHttpManager
initReq <- parseUrl url
let req = g $ initReq { checkStatus = \_ _ _ -> Nothing :: Maybe SomeException }
resp <- liftIO . withSocketsDo $ httpLbs req mgr
let st = responseStatus resp
if statusIsSuccessful st
then do
timeLog $ "SUCCESS: ResponeStatus of " ++ show (responseStatus resp) ++ " connecting to URL " ++ url
timeLog $ "Response body: " ++ show (responseBody resp)
return $ responseBody resp
else do
timeLog $ "ERROR: There was an HTTP error, connecting to: " ++ url ++ " with response body: " ++ show (responseStatus resp)
throwM $ StatusCodeException st (responseHeaders resp) (responseCookieJar resp)