djacobs / PyAPNs

Python library for interacting with the Apple Push Notification service (APNs)
http://pypi.python.org/pypi/apns/
MIT License
1.22k stars 374 forks source link

read_error_response thread dead-loop #86

Closed lbjworld closed 9 years ago

lbjworld commented 10 years ago

read_error_response thread seems like fall into dead-loop when i try to send notification with invalid token. (got error-response status : 8) error logs as follow : [INFO] apns: resending 2981 notifications to APNS [INFO] apns: got error-response from APNS:(8, 0) [INFO] apns: rebuilding connection to APNS [INFO] apns: resending 2972 notifications to APNS [INFO] apns: got error-response from APNS:(8, 0) [INFO] apns: rebuilding connection to APNS [INFO] apns: resending 2980 notifications to APNS [INFO] apns: got error-response from APNS:(8, 0) [INFO] apns: rebuilding connection to APNS [INFO] apns: got error-response from APNS:(8, 0) [INFO] apns: rebuilding connection to APNS [INFO] apns: resending 2971 notifications to APNS [INFO] apns: resending 2979 notifications to APNS [INFO] apns: got error-response from APNS:(8, 0) [INFO] apns: rebuilding connection to APNS [INFO] apns: got error-response from APNS:(8, 0) [INFO] apns: rebuilding connection to APNS [INFO] apns: resending 2979 notifications to APNS [INFO] apns: resending 2970 notifications to APNS [INFO] apns: got error-response from APNS:(8, 0) [INFO] apns: rebuilding connection to APNS [INFO] apns: resending 2981 notifications to APNS [INFO] apns: got error-response from APNS:(8, 0) [INFO] apns: rebuilding connection to APNS [INFO] apns: resending 2975 notifications to APNS

anyone got this problem ?

ahawks-mmf commented 10 years ago

I have run into this with enhanced=True. Wasn't sure what caused it, but it resulted in a few users getting spammed with dozens of push notifications within seconds.

jimhorng commented 10 years ago

The behavior for enhanced notification is that when error-response received, all notifications sent between the notification in prior to error one and last sent, will be resent. please refer to https://github.com/djacobs/PyAPNs#enhanced-message-with-immediate-error-response. The premise is that you have to set notification's identifier uniquely in order for "resent worker" to identify which notification is the error one.

identifier = random.getrandbits(32)
apns_enhanced.gateway_server.send_notification(token_hex, payload, identifier=identifier)