Not all notifications got response
Hi,
Do anybody experience the problem, that each hour pushy does not get response to some sent notifications from Apple. That happens at the time when auth token expires (it happens for about one hour and ten minutes when it is issued). Count of unanswered notifications depends on how many notifications are sent through connection. Seems that 50 notifications per second are enough.
It could be reproduced with following conditions. Say for example you have 8 threads where each tries to send 10 notifications at the same time. And for example you do it once a minute. When auth token expires, and you send next time, pushy receives response about expired token for some first notifications, but for all other remaining there is no response at all. It looks like that Apple when it receives new auth token in some way fails to respond on notifications with old token that it receives shortly after that. These numbers of threads and notifications I found empirically and with them this situation could be reproduced consistently. Also have tried to comment out auth token change and continue to send with expired token. on first attempt have not got response on all sent notifications, but on next iterations all notifications are responded. So it looks like a problem at Apple side, but would be nice if somebody can clarify. My pushy version is 0.10 and netty is 4.1.11.Final.
Thanks, Z.
P.S> when tested, I have sent all notifications to the same device.
Hi @jchambers.
Could it be possible to add optional configurable time to live to TokenAuthenticationApnsClientHandler::authenticationToken. So when token is created, handler would schedule token recreation after some time. It could live together with current token expiration handling. Hope that then lost response problem would go away if token TTL is set less than one hour.
Seems that there is another problem with lost responses. It happens in our production environment about once per week. Monitoring system shows that couple thousand notifications do not receive response in short time and we manually cancel them (Future<PushNotificationResponse
Thanks, Z.
If you'd be so kind, could you share (probably as a gist?) logs at the TRACE level around a token expiration? It'd be helpful if we could see the traffic from the server for notifications before the expiration, notifications sent with the expired token, and a notifications sent with the new token.
Could it be possible to add optional configurable time to live to TokenAuthenticationApnsClientHandler::authenticationToken.
We'll consider it if this turns out to be an unavoidable server-side problem, but I'm not yet convinced that's the case (i.e. I'm still willing to believe it's on our end).
From debug it seems that ApnsClientHandler::close is not called and therefore responsePromises are lost on channel close. May be responsePromises cleanup could be moved to some other place, seems that ApnsClientHandler::channelInactive would be fine.
Could you please open a separate issue for this problem?
Thanks!
Hi, Jon.
There is gist: https://gist.github.com/janzar/3698e595d1fb8fa9309c177315a2434f. It contains both log file and application used to generate it. I have changed pushy a little bit:
TokenAuthenticationApnsClientHandler:
long keyShift = 67L * 60L * 1000L; Date issuedAt = new Date(System.currentTimeMillis() - keyShift); this.authenticationToken = new AuthenticationToken(signingKey, issuedAt);
and removed some fields from log file. Test application works following: once a minute it tries to send a batch of 50 pushes. As I create token with time set to 67 minutes ago, after little more than 3 minutes of creation it expires. So all pushes in first three batches get response, but only fraction in 4th batch (pushes that didn't got response within 40 seconds are canceled by timer) and all again in 5th batch.
Could you please open a separate issue for this problem?
Created #480 for it.
Thanks for the logs; this is a big help! Will dig in and see what I can figure out as soon as possible.
Thank you!
I've done some more investigation and discovered some surprising behavior. As soon as we send a push notification with an expired token, we get a new SETTINGS frame from the APNs server:
[id: 0x9f0b0f7c, L:/192.168.50.11:49491 - R:api.push.apple.com/17.188.155.26:443] SETTINGS: ack=false, settings={HEADER_TABLE_SIZE=4096, MAX_CONCURRENT_STREAMS=1, INITIAL_WINDOW_SIZE=65535, MAX_FRAME_SIZE=16384, MAX_HEADER_LIST_SIZE=8000}
The notable thing here is MAX_CONCURRENT_STREAMS=1, which then leads to a a few frames being reset as follows:
[id: 0x9f0b0f7c, L:/192.168.50.11:49491 - R:api.push.apple.com/17.188.155.26:443] RST_STREAM: streamId=25, errorCode=7
[id: 0x9f0b0f7c, L:/192.168.50.11:49491 - R:api.push.apple.com/17.188.155.26:443] RST_STREAM: streamId=25, errorCode=5
Error codes 7 and 5 are "refused stream" and "stream closed," respectively (we get two messages because we had already sent a HEADERS and DATA frame for the given stream before getting the SETTINGS or RST_STREAM frames from the server).
There are two conclusions to draw here:
- Within Pushy, we are not handling
RST_STREAMframes correctly, and should be able to handle this problem without losing notifications. This will be our first priority. - The behavior of the APNs server, while technically legal, is a little surprising. I'll make some noise to make sure that's intentional and not a bug.
In any case, I think we have enough evidence to understand what's causing this problem and to understand that it's within our power to fix.
Hi, Jon.
Looks like it is the root cause of the problem. Great that you find it! Would like to know is there any plan when v0.10.1 could be released?
Thanks, Z.