python-hyper/hyper

Timeout handling

farefernandez opened this issue · 12 comments

Hi,

I'm using Hyper to connect to a HTTP/2 website and I'd like to be able to control timeouts (connection, read, dns resolver).

I don't seem to be able to find mentions to timeout handling in the documentation so I assume this could be seen as a feature request.

Thanks!

Yup, this seems like a good feature request to me!

Thanks Cory.

API-wise, we could have one global, coarse-grained timeout parameter which could refer to the sum of all of the components (connect, read, dns). This is what people usually should use.

Fine-grained timeouts could be added with specific parameters controlling each of the components.

For reference, this is how requests does it (although the dns resolver timeout doesn't seem to be handled): http://docs.python-requests.org/en/latest/user/advanced/#timeouts

Relevant DNS resolver discussion: https://bugs.python.org/issue22889

Thanks!

@farefernandez I'm a bit nervous about implementing an extremely complex timeout logic. However, if you were going in that direction the thing to do is to look at urllib3's Timeout logic and see if we can implement something somewhat similar.

Hi All,

I'm getting this error consistently on response.read()

ssl.SSLError: ('The read operation timed out',)

Does this issue mean that this can't be handled currently?

Thank you for hyper!

@johnwheeler I think that depends on what you mean by "handled". What would you define as handled here?

Thank you for the quick response. Handled was a poor word choice since it connotes exception handling. I was wondering if there's a way to stop this error from occurring and proceed to read the data, and I want to confirm that:

  1. There's no way to do that per this issue (no way to set a timeout)
  2. I'm not misunderstanding the HTTP/2 protocol and this error makes it immediately apparent to you how.

Thanks again

Please disregard. I just don't know what I'm doing. I think I'm trying to interact with a HTTP/2 service in an HTTP/1 way and didn't make it far enough in your docs. I've gotten further along now, and it looks like I'm making headway.

FYI - I'm using this library to connect to the Alexa Voice Service, which is Amazon's Echo service for building the Echo into your own hardware.

Ah I'm glad you've worked it through!

Hi,

I deleted my last comment because I realized HTTP20Connection's connect is not part of the public API.

Does it make sense to add to add a timeout parameter to HTTPConnection init method that is used during socket creation?

i.e. in HTTP20Connection.connect, it'd be something like:

sock = socket.create_connection((host, port))
sock.settimeout(self._sock_timeout)

If this is a good idea, I can attempt a PR

@johnwheeler I would accept a PR that does that, yeah. =)

Is controlling timeout not yet?

If not, does it have a timeout internally used by default?