SSL3_WRITE_PENDING error
After some time service using PyAPNS is run in background I start to get such error: return self._sslobj.write(data) SSLError: [Errno 1] _ssl.c:1217: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
After restarting service everythong works perfect. I use send_notification method for sending messages to all registered devices in simple for cycle.
This problem is still present in the current version.
StackOverflow question: https://stackoverflow.com/questions/12042932/pyapns-ssl3-write-pending-error
A stacktrace for reference:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/username/public_html/py/app/views.py", line 44, in apple_notifications
send_apple_notification(form.token.data, form.uri.data, form.message.data)
File "/home/username/public_html/py/app/views.py", line 15, in send_apple_notification
apns.gateway_server.send_notification(token, payload)
File "/usr/local/lib/python2.7/dist-packages/apns.py", line 293, in send_notification
self.write(self._get_notification(token_hex, payload))
File "/usr/local/lib/python2.7/dist-packages/apns.py", line 141, in write
return self._connection().write(string)
File "/usr/lib/python2.7/ssl.py", line 236, in write
return self._sslobj.write(data)
SSLError: [Errno 1] _ssl.c:1311: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
On line 15 of "/home/username/public_html/py/app/views.py" is this:
12 def send_apple_notification(token, uri, message):
14 payload = Payload(alert=message, sound="default", custom={"custom":{"uri":uri}})
15 apns.gateway_server.send_notification(token, payload)
On line 293 of "/usr/local/lib/python2.7/dist-packages/apns.py" is this:
292 def send_notification(self, token_hex, payload):
293 self.write(self._get_notification(token_hex, payload))
On line 141 of "/usr/local/lib/python2.7/dist-packages/apns.py" is this:
140 def write(self, string):
141 return self._connection().write(string)
On line 231 of "/usr/lib/python2.7/ssl.py" is this:
231 def write(self, data):
233 """Write DATA to the underlying SSL channel. Returns
234 number of bytes of DATA actually transmitted."""
235
236 return self._sslobj.write(data)
@alexbutum pull requests #25 + #21 are an attempt to resolve this
There was one more issue I found even after merging #25 + #21:
http://stackoverflow.com/questions/23759967/pyapns-sending-push-notification-to-more-than-one-device-token-not-working
Regards, -Ghulam Muhammad
Was this ever fixed in another commit?
Also just remembered I saw @djacobs comment on the same issue in @simonwhitaker's old repo here back in January too: https://github.com/djacobs/PyAPNs/pull/23. Looks like this wasn't ever officially merged in as a fix in that repo either.
The bug & fix aren't well documented here, and the merge isn't clean. I am happy to discuss more if anyone is willing to summarize all the content in one place, but I'm generally going to be very conservative about these kinds of merges.
@djacobs I think the answerer in https://stackoverflow.com/questions/12042932/pyapns-ssl3-write-pending-error has a pretty good summary. Does that help?
It's helpful! But for me to accept the commit (many people use this software!) I'd like it all tied up in one place - problem statement, solution, patch, all in one github ticket (right now it's spread out over 3 or 4). I'm trying to be ticky-tacky, just trying to keep it simple.
Thanks, David
What are the other tickets? (I propose we can ignore those in other repos.) I can take a stab at organizing.
I am able to reproduce this right now. What information can I provide that would help?
Below is what I am seeing in the logs. I haven't isolated a set of specific procedures to reproduce -- but a rough summary would be -- run pyapns and after a certain amount of time eventually this appears in the logs after sending hundreds to thousands of push notifications.
apns: 2014-08-05 16:16:50,659 - INFO - 505 - sending notification with id:674199962 to APNS failed: <class 'ssl.SSLError'>: [Errno 1] _ssl.c:1296: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
Is this your fork: https://github.com/dZkF9RWJT6wN8ux/PyAPNs? It looks like it is in sync - per https://github.com/dZkF9RWJT6wN8ux/PyAPNs/compare/djacobs:master...master
Thanks!
On Tue, Aug 5, 2014 at 10:13 AM, Alex Butum [email protected] wrote:
I have merged the fixes from #21 https://github.com/djacobs/PyAPNs/pull/21 and #25 https://github.com/djacobs/PyAPNs/pull/25 a while back into my own fork and that fixed the problem. I'll try to provide my updated fork for reference.
— Reply to this email directly or view it on GitHub https://github.com/djacobs/PyAPNs/issues/13#issuecomment-51228903.
@dZkF9RWJT6wN8ux Any luck?