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

TimeoutTriggered exception on most requests for http-client > 0.4.7.1 #116

Closed
rickdzekman opened this Issue Apr 11, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@rickdzekman

rickdzekman commented Apr 11, 2015

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 to Network.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)

snoyberg added a commit that referenced this issue Apr 12, 2015

@snoyberg

This comment has been minimized.

Show comment
Hide comment
@snoyberg

snoyberg Apr 12, 2015

Owner

I've just reverted the custom timeout code and released a new version to Hackage. Can you test out the newest http-client and let me know if it resolves your issue?

Owner

snoyberg commented Apr 12, 2015

I've just reverted the custom timeout code and released a new version to Hackage. Can you test out the newest http-client and let me know if it resolves your issue?

@rickdzekman

This comment has been minimized.

Show comment
Hide comment
@rickdzekman

rickdzekman Apr 13, 2015

I won't be able to give it a try for a few hours, but when I do I'll let you know.

rickdzekman commented Apr 13, 2015

I won't be able to give it a try for a few hours, but when I do I'll let you know.

@rickdzekman

This comment has been minimized.

Show comment
Hide comment
@rickdzekman

rickdzekman Apr 13, 2015

That seemed to do the trick. Worked fine on http-client ==0.4.11.1

rickdzekman commented Apr 13, 2015

That seemed to do the trick. Worked fine on http-client ==0.4.11.1

@snoyberg

This comment has been minimized.

Show comment
Hide comment
@snoyberg

snoyberg Apr 13, 2015

Owner

Cool, thanks for testing.

Owner

snoyberg commented Apr 13, 2015

Cool, thanks for testing.

@snoyberg snoyberg closed this Apr 13, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment