Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Push Notifications reported as sent and without error but not received in case of ~ 20 notifications #79

Closed
lukasnagl opened this issue Sep 29, 2014 · 18 comments

Comments

@lukasnagl
Copy link

In case we send a certain amount of push notifications, they don’t seem to be delivered correctly. Everything works correctly for a lower amount of push notifications. We do not use persistent connections.

Here’s some very rough logging code that we had in place:

    client.push(*notifications)
    Rails.logger.info "PNS Job (1/2): Send #{notifications.length} notifications. Notification Sample: #{notifications.first.inspect}. Errors: #{notifications.collect(&:error).compact}. Sent: #{notifications.collect(&:sent?)}"
    Rails.logger.info "PNS Job (2/2): #{client.devices}, Push Infos: #{push_options.inspect}"

All following examples were created with the production build of the app, using the production certificate and Houston production client with houston 2.2.1.

Here’s the log output of a working example. As you can see, the errors are empty and both notifications are reported as being sent, and they are correctly received on both clients.

PNS Job (1/2): Send 2 notifications. Notification Sample: #<Houston::Notification:0x000000070bb240 @token="<REPLACED>", @alert="Some Text", @badge=1, @sound=nil, @category=nil, @expiry=nil, @id=0, @priority=nil, @content_available=true, @custom_data={:custom_data=>{:rscs=>[{REPLACED}]}}, @sent_at=2014-09-26 10:15:13 +0200>.
Errors: []. Sent: [true, true]
PNS Job (2/2): [], Push Infos: {:alert=>"Some Text", :badge=>1, :content_available=>true, :custom_data=>{:rscs=>[{REPLACED}]}}

Here’s the log output of an example that does not work. Again, the errors are empty and all notifications are reported as being sent, but they are not in fact received on the target devices. The target devices include the two devices from the previous working example:

PNS Job (1/2): Send 23 notifications. Notification Sample: #<Houston::Notification:0x0000000c8dc488 @token="<REPLACED>", @alert="Some Alert", @badge=1, @sound=nil, @category=nil, @expiry=nil, @id=0, @priority=nil, @content_available=true, @custom_data={:custom_data=>{:rscs=>[{REPLACED}]}}, @sent_at=2014-09-29 15:33:36 +0200>.
Errors: []. Sent: [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true]
PNS Job (2/2): [], Push Infos: {:alert=>"Some Alert", :badge=>1, :content_available=>true, :custom_data=>{:rscs=>[{REPLACED}]}}

What could be the source of the error or what else could we look into to narrow down the problem?

@micred
Copy link

micred commented Sep 29, 2014

See #72

@lukasnagl
Copy link
Author

@micred Is this really the same issue? It seems to me that #72 is based on the presence of invalid tokens. The invalid tokens are retrieved in the code sample:

Rails.logger.info "PNS Job (2/2): #{client.devices}

And in both provided examples the resulting array in the logs is empty, meaning that Houston reports that there was no invalid token used.

@micred
Copy link

micred commented Sep 29, 2014

I don't know exactly. Try progressively remove a device token until (maybe) you find the bad token amount them and then they will start again.

@micred
Copy link

micred commented Sep 30, 2014

mmm... I don't know if it solve your problem but I find that adding a sleep solve my problem.
I'm curious if it also solve your problem, can you try using Persistent Connections and adding sleep(0.5) between each connection.write(notification.message)?

Thank you.

@micred
Copy link

micred commented Sep 30, 2014

Further details:
http://redth.codes/the-problem-with-apples-push-notification-ser/
Grocer similar bug: grocer/grocer#14

@lukasnagl
Copy link
Author

I’ve tried switching to persistent connections and the sleep like you suggested and hit issue #77, Errno::EPIPE (Broken pipe).

@micred: Would you suggest to try out #73 or should I try to use http://joshsymonds.com/blog/2013/10/17/sidekiq-plus-houston-production-ready/?

@lukasnagl
Copy link
Author

I tried using pull request #73, but to no avail. Still hitting issue #77.

@elado
Copy link

elado commented Oct 10, 2014

Same problem here. Got no error from this gem, but tried sending with https://github.com/noodlewerk/NWPusher and got invalid token error.

@kaneda
Copy link

kaneda commented Oct 14, 2014

Already commented on #72 but the quick workaround is to send each notification separately

@elado
Copy link

elado commented Oct 14, 2014

@kaneda I do, and errors are still empty.

@kaneda
Copy link

kaneda commented Oct 14, 2014

@elado yes, it won't return a proper error, but at least the rest of your notifications won't be dropped

@sgwilym
Copy link

sgwilym commented Oct 14, 2014

@kaneda Doesn't sending each notification separately mean opening a new connection for each notification?

@kaneda
Copy link

kaneda commented Oct 14, 2014

@sgwilym it does, unfortunately.

@evrenios
Copy link

any fix found for this issue, i gave a wrong token to test and i noticed that it didn't raise any error so error is still nil of the notification even tho its random characters.

@LuizEdgar
Copy link

Hello, this issue was solved? If no, how are you handling this?

@kaneda
Copy link

kaneda commented Apr 14, 2015

@LuizEdgar, not to the best of my knowledge, instead I send each notification separately to users instead of en masse.

@LuizEdgar
Copy link

Thanks @kaneda.

Well... but Apple says that it can be considered as an DoS Attack.

"Keep your connections with APNs open across multiple notifications; don’t repeatedly open and close connections. APNs treats rapid connection and disconnection as a denial-of-service attack. You should leave a connection open unless you know it will be idle for an extended period of time—for example, if you only send notifications to your users once a day it is ok to use a new connection each day."

How bad can it be? How many notifications are you sending per day?

@kaneda
Copy link

kaneda commented Apr 14, 2015

@LuizEdgar it could be considered a DoS attack. I'm not sending many, in the hundreds.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

9 participants