aesiniath / http-streams

Haskell HTTP client library for use with io-streams
https://hackage.haskell.org/package/http-streams
BSD 3-Clause "New" or "Revised" License
50 stars 48 forks source link

Timeouts? #93

Open laurencer opened 9 years ago

laurencer commented 9 years ago

How does this library handle timeouts? I can't see anywhere to specify them (or whether there is an implicit default). Everything just goes from Connection -> Request -> IO a (or something like that) where neither Connection nor Request have any connection-level concerns (like timeouts).

Haxr depends on it for sending HTTP requests, and appears to be failing with timeouts when used from confluence-sync against a slow Confluence instance (> 5 second request latency).

Is there anything I'm missing in this library, or have I been lead down the wrong path by error messages somewhere in my stack?

laurencer commented 9 years ago

So found the issue. Timeouts are set on the socket itself (not via io-streams).

By using network-socket-options (or alternatively just the plain Network.Socket interface), you can add in a couple of IO actions that set the timeouts.

For example (for the openConnection function).

    s <- socket f Stream defaultProtocol

    let timeoutMicros = 60000000 -- 60 seconds
    setRecvTimeout s timeoutMicros
    setSendTimeout s timeoutMicros

This also needs to be done for openConnectionSSL.

I haven't issued a pull request because I'm not sure how you want to expose access to the Socket or timeouts via the API. Any ideas @afcowie ?

laurencer commented 9 years ago

For an example - see the manual/hardcoded workaround in https://github.com/laurencer/confluence-sync/blob/master/vendor/http-streams/lib/Network/Http/Connection.hs#L179

istathar commented 9 years ago

@laurencer Thanks for digging into this. I actually just fired up IRC to start asking around.

Exposing what was an internal detail to user configuration is a tough one. It's supposed to be in the domain of "just works", but this isn't the first time meddling with the connection code has come up. Timeout is a fairly pervasive concept, and we really ought to support adjusting it.

I'll have a look at a few of the other open issues and see if there's a common enough thread to justify an API smash. bbiab.

AfC