-
Notifications
You must be signed in to change notification settings - Fork 331
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
add timeouts for transport.dialtls and http.client #22
Conversation
It would probably be a lot better to just allow users to directly modify the HTTPClient's transport. Faking "optional" parameters like this is not a clean solution. |
For example, I believe right now we could do this: c := apns2.Client(cert)
c.HTTPClient.Transport.DialTLS = func.... So I think a PR isn't even needed. |
@dwieeb I also thought about setting the dialer via |
|
I'm not certain it's a good idea to set this default in the actual library without any kind of retry logic. I feel like this should just be documented describing the problem with example code on how to set the tls timeout. |
I believe timing out should be handled on package level. Other libraries in other languages (such as lowdown) handle timeouts internally. This way, even if no further steps are taken by the package user, at least system resources are freed and running goroutines are finalized. Since redialing does not guarantee a connection, retrying to send the push is an implementation decision and should be left to the user. Edit: After some thought, I partially take that back. It might make sense to cover some basic retry scenarios, such as retrying x times or retrying for x minutes. However, I think these features should be available under a different function such as @sideshow Any thoughts? |
@c3mb0 Oh no, that's not true... I hit the issue again. |
@zjx20 Strange, it is working consistently for us. Which version of Go are you using? |
@c3mb0 As I observed, it is not a handshake problem in my case. If a connection (from apns2 to apple server) become idle (e.g. keep alive for 10 minutes without sending any request), and then we use it to send requests again, the apple server just refuse to read incoming data. I could see the "Send-Q" column from A workaround for my case is to specify a It is hard to tell, maybe your changes are necessary as well. |
@zjx20 As you mentioned, lack of I know there has been a lot of back and forth, but I'm reverting This is the setup we are running in production and it seems to handle all faulty requests so far. |
Does this patch need to be made compatible with go 1.4.3? |
Thanks for this, I think we are close. The x/net/http2 package has deleted pre-Go1.5 request cancellation (hence the build fail), as it was buggy, so I am thinking of removing support for 1.4.3 and making 1.5 the minimum now that 1.6 is stable. Also the Timeout property on the http.Client is go 1.6+ so we probably need to do something conditional for 1.5 |
After a few days of usage, it seems like an |
I think there is limited benefit to having a timeout that is even this aggressive. I would recommend 20 seconds - the default linux TCP connection timeout. Setting the timeout to be 3 seconds means that someday when apple's apns service is at capacity where the 3 second timeout is triggered then any apns client with a higher timeout will be able to deliver push notifications, and any apns client with a lower timeout will be not be able to deliver any push notifications at all. |
Can we build the retry logic into the actual client? That way we wouldn't need an additional method in the API. It would just be: client := apns2.NewClient()
client.RetryAttempts = 10
client.RetryDuration = 20 * time.Second
client.Push(notification) The retry logic would be built in to the |
@sideshow What would need to be done, exactly, for 1.5? Wouldn't it not compile? |
Hey @c3mb0 thanks - I cherry picked your code and pushed back another pull request here #25. This is essentially your code with the timeouts set as vars. I agree that its bad having to set defaults for the HTTPClient, but I think its important out of the box for this to only return one of two things - A success or a failure. Without these defaults sadly theres a third shitty case as we know where it just doesn't return which is not good. I think this patch is an OK middle ground because at least the defaults can be configured. I have left them pretty large because being HTTP there is always going to be issues with latency, proxys, etc. As @chimpmaster72 said, the default linux TCP connection is 20seconds. As far as the retry logic goes, my thoughts are that this should be a higher level package which handles retries, queing, channels etc. |
Hey @dwieeb in answer to your question; In 1.5 I was getting Also, For go 1.4 looks like some of the internals in x/net/http2 have been changed and they removed the request cancellation in golang/net@b797637 |
Closing this in favour of the recently merged timeout code. |
Workaround for #17 and #20.
Discussed in detail in #20.