Destroy the gateway connection on error, so reconnection works also when the connection is dropped instead of closed. #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When an error occurs and the apns server drops the connection, sometimes the live agent does not reconnect correctly. Apparently the 'close' event is not fired when when the connection is dropped suddenly from the remote side.
I was able to reproduce this by sending lots of notifications to non-existing device tokens (and thus receiving error 8). Be careful when testing this though, at some point the server stopped accepting my connections :)
Because by design the apns server always closes the connection on error (see the docs), it is safe to destroy the gateway on our end when encountering an error. This results in the close event being fired and the reconnection being started.
I'm not sure, but I guess this is also the source of the problems in issue #1, the behavior that is described there is exactly what I encountered when discovering this issue.