http-client icon indicating copy to clipboard operation
http-client copied to clipboard

Timeout doesn't work on Windows

Open ndmitchell opened this issue 8 years ago • 3 comments

Given the example (based on code modified from here):

import           Network.HTTP.Client
import           Network.HTTP.Client.Conduit (bodyReaderSource)
import           Network.HTTP.Client.TLS     (tlsManagerSettings)
import           Network.HTTP.Types.Status   (statusCode)

main :: IO ()
main = do
    manager <- newManager tlsManagerSettings
    request <- parseRequest "http://httpstat.us/200?sleep=10000" -- 10s

    withResponse request{responseTimeout = responseTimeoutMicro 5000000 {- 5s -}} manager $ \response -> do
        putStrLn $ "The status code was: " ++ show (statusCode $ responseStatus response)

This connects to a website that returns after 10s, and then runs a response with a 5s timeout. I expect it to wait 5s then fail. In actual fact, it waits 10s. Setting the timeout incredibly low (~100000 microsecs, 0.1s) does cause a timeout, so I assume the initial part of the work is preemptible, but the main part of it isn't. It also seems to often stop responding to Ctrl-C, so I'm guessing something is masked or the wrong type of safe/unsafe FFI call somewhere. Setting the timeout on the server to a ridiculous value (e.g. an hour) doesn't seem to make it abort with a timeout.

Versions: Windows 10, GHC 8.2.1, http-client 0.5.7.0.

CC @pepeiborra

ndmitchell avatar Sep 24 '17 21:09 ndmitchell

This may be related to this GHC issue:

https://ghc.haskell.org/trac/ghc/ticket/8684

snoyberg avatar Sep 25 '17 10:09 snoyberg

FWIW using race from the async package does not help to build a workaround: the withResponse call does not yield to uninterruptibleCancel. GHC issue seems likely.

pepeiborra avatar Sep 25 '17 12:09 pepeiborra

Same issue with responseTimeoutMicro is in OS X, same versions of GHC/http-client.

swamp-agr avatar Oct 01 '17 22:10 swamp-agr