If we don't reset the failure count then the pending notification queue
will stall without warning. Instead it seems fair that if the
application continues to send notifications then we give it another
shot and attempt 3 more times.
This has the effect of never really "hard" failing but all notifications
are handled and the application can take responsibility for abandoning
the worker if they are monitoring the errors correctly.
We need to ensure a stream has entered the `_streamIds` array so we can
loop over it if an error occurs.
If an error occurs we need to clean up old streams by bubbling the error
through to them, allowing their corresponding promise to be rejected. If
the error doesn't make it through the promise will stall forever.
An error occurring between a stream being created (popping it from the
client queue) and having data written (when it would normally be
allocated an ID) then it can end up in limbo because looping through
`streamIds` would not hit that stream.
Using the built-in available stream count was not suitable as it is
managed on a different schedule to that which we require. `createStream`
would not increment he used stream count until a frame was actually sent
whereas we want to identify a stream as in-use as soon as it is acquired
so we shall maange a local count.
We know that APNS will send a stream limit immediately after connection
and given the current state of node-http2 we have to start with an
initial stream limit of 0 until that comes through. As such it is
redundant to emit wakeup immediately after connection because we won't
be able to do anything.
In addition, if we do go back to having an infinite stream limit
initially we don't want to flood a single endpoint with streams when we
could distribute it across multiple. (Imagine a call to
`pushNotification` with 10,000 tokens all piling onto a single
connection).
The streamSlotsFree logic within connection is broken with the Infinity
value. As we know that APNS will always set a stream limit on connect we
set the values to 0 immediately and allow the incoming SETTINGS frame to
update and begin the process.