Skip to content
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

APNS notification gives the wrong feedback #154

Closed
jiajiawang opened this issue May 15, 2015 · 16 comments
Closed

APNS notification gives the wrong feedback #154

jiajiawang opened this issue May 15, 2015 · 16 comments

Comments

@jiajiawang
Copy link

Log says delivered but nothing arrives on the phone.
If I use the same certificate and device token in NWPusher, I will get 'APN invalid token'.
As the phone doesn't actually receive anything, I assume NWPusher is giving the right feedback.

Also this bad delivery will destroy all the following good deliveries.
When sending multiple notifications at once, a good delivery (valid token) in front of the bad delivery (invalid token) will be successfully delivered.
But if a good delivery is after the bad delivery, it won't be successfully delivered.
However the log still says delivered.

I'm using ruby 2.1.2, rpush 2.4.0.

@jiajiawang
Copy link
Author

I figured out the cause of 'invalid token'.
I'm sending a push notification to a sandbox device token with a production certificate, and vice versa.
It can be easily reproduced.

@tritter
Copy link

tritter commented May 18, 2015

Yes I have exactly the same problem. Apple closes the connection after it sends an Invalid Token (8). In my apps I'm always sending notifications in a batch, and some tokens actually are sandbox tokens or invalid tokens. I'm afraid I need to switch to another gem.

I think this issue is the same as these:
ileitch/rapns#159
#7

@ileitch
Copy link
Member

ileitch commented May 18, 2015

@tritter Rpush should mark the rest of the batch as failed once the Invalid Token error is received. What do you see in the logs when the error is received?

@tritter
Copy link

tritter commented May 18, 2015

No he deletes all notifications! Note: I added the following in the initialiser:

on.notification_delivered do |notification|
    notification.destroy
end

I see some crash in the logs, maybe this is the problem?
But I thought this wouldn't cause the crash because its reflective. But the error could be nil actually:

on.notification_failed do |notification| 
  Rails.logger.error "Failed to deliver notification: #{notification.error_code} - #{error.error_description}" 
end

LOGS:

NameError, undefined local variable or method `error' for main:Object

[2015-05-18 14:01:13] [ERROR] [ios_app] Invalid token (8)
[2015-05-18 14:01:13] [ERROR] [ios_app] Lost connection to gateway.push.apple.com:2195, reconnecting...
[2015-05-18 14:01:16] [ERROR] NameError, undefined local variable or method `error' for main:Object
/home/deployer/apps/roosterapp/production/releases/20150511151542/config/initializers/rpush.rb:62:in `block (2 levels) in <top (required)>'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/reflection_collection.rb:37:in `call'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/reflection_collection.rb:37:in `__dispatch'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/reflectable.rb:6:in `block in reflect'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/reflectable.rb:4:in `each'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/reflectable.rb:4:in `reflect'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:123:in `block (2 levels) in complete_failed'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:122:in `each'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:122:in `block in complete_failed'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:120:in `each'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:120:in `complete_failed'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:102:in `block in complete'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:100:in `each'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:100:in `complete'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:84:in `block in notification_processed'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:82:in `synchronize'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/batch.rb:82:in `notification_processed'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/gcm/delivery.rb:29:in `ensure in perform'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/gcm/delivery.rb:29:in `perform'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/dispatcher/http.rb:12:in `dispatch'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/dispatcher_loop.rb:61:in `dispatch'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/dispatcher_loop.rb:35:in `block (2 levels) in start'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/dispatcher_loop.rb:25:in `loop'
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/dispatcher_loop.rb:25:in `block in start'
[2015-05-18 14:01:16] [ERROR] Rpush::DeliveryError, Unable to deliver notification 5990, received error (Failed to deliver to all recipients. Errors: NotRegistered.)
/home/deployer/apps/roosterapp/production/shared/bundle/ruby/2.1.0/gems/rpush-2.4.0/lib/rpush/daemon/gcm/delivery.rb:89:in `handle_failures'

@ileitch
Copy link
Member

ileitch commented May 18, 2015

notification_failed doesn't take an error argument, it'll always fail with that error.

@tritter
Copy link

tritter commented May 18, 2015

Yes! That looks like a stupid mistake -_- I'll redeploy and let you know if it will save the sandbox keyed notifications now.

@jiajiawang
Copy link
Author

My current problem is that rpush is not receiving invalid token error at all.

@tritter
Copy link

tritter commented May 19, 2015

@jiajiawang maybe its the logger you're using? Did you change the default init file in some way?

Here is mine

  # Path to write PID file. Relative to current directory unless absolute.
  config.pid_file = 'tmp/pids/rpush.pid'

  # Path to log file. Relative to current directory unless absolute.
  config.log_file = 'log/rpush.log'

  config.log_level = (defined?(Rails) && Rails.logger) ? Rails.logger.level : ::Logger::Severity::DEBUG

  # Define a custom logger.
  config.logger = Rails.logger

@tritter
Copy link

tritter commented May 19, 2015

@ileitch My app just delivered another batch of notifications. There seems to be only one sandbox token left I didn't delete.
You said that the notifications should be marked as failed. But the rpush_notifications table is empty. So all notifications still went through notification_delivered I suppose?

on.notification_delivered do |notification|
    notification.destroy
end

This was my log:

[2015-05-19 09:00:15] [ERROR] [ios_app] Invalid token (8)
[2015-05-19 09:00:15] [ERROR] [ios_app] Lost connection to gateway.push.apple.com:2195, reconnecting...

@jiajiawang
Copy link
Author

@tritter, here is something new I found.
Rpush will only report invalid token error if I run it as a deamon 'rpush start'.
However it won't report the error if I use 'Rpush.push' or 'rpush push'.
@ileitch, is this how it supposed to be?

@tritter
Copy link

tritter commented May 22, 2015

UPDATE: after removing this handler:

on.notification_delivered do |notification|
    notification.destroy
end

I am able to see the failed notification in the DB. @ileitch am I using the wrong callback to delete a delivered notification? I want to see only the failed ones not the successful delivered ones.
But with APNS notifications in the current implementation. The handler 'on.notification_delivered' is called first and after APNS returns an error the notification is already deleted (in the way I implemented it). Shouldn't there be a method 'on.notification_delivered_successfull' after a timeout and seeing that there are no errors in the case of APNS?

@thiensubs
Copy link

Yes, I has the same isssue. I can't push any notification for apn (apple).
Who can help me to fix it?
Any idea?

@jiajiawang
Copy link
Author

@thiensubs Are you using 'Rpush.push'?
If so, try 'rpush push' instead.

@thiensubs
Copy link

No. I'm using rpush start. This is a deamon mode. This is message i looking
at log/rpush.log

On Saturday, June 20, 2015, Jiajia Wang notifications@github.com wrote:

@thiensubs https://github.com/thiensubs Are you using 'Rpush.push'?
If so, try 'rpush push' instead.


Reply to this email directly or view it on GitHub
#154 (comment).

-----------------------------------------------------------------------Chào
thân ái và quyết thắng...

Trong đời có hàng trăm cái lý ngang với chân lý, nhưng chân lý là duy
nhất!

Tiến An ^_^ BS Phone: 0127.3851.881

@jiajiawang
Copy link
Author

I'm not seeing the log.

@ileitch
Copy link
Member

ileitch commented Jun 27, 2015

This should now be fixed in master. I'll release a new version soon.

@ileitch ileitch closed this as completed Jun 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants