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

SSL3_WRITE_PENDING error #13

Open
ilyapuchka opened this issue Aug 20, 2012 · 12 comments
Open

SSL3_WRITE_PENDING error #13

ilyapuchka opened this issue Aug 20, 2012 · 12 comments

Comments

@ilyapuchka
Copy link

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.

@alibitek
Copy link
Contributor

alibitek commented Mar 6, 2014

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)

@thetylerhayes
Copy link

@alexbutum pull requests #25 + #21 are an attempt to resolve this

@ghulam-muhammad-gvs
Copy link

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

@thetylerhayes
Copy link

Was this ever fixed in another commit?

@thetylerhayes
Copy link

Also just remembered I saw @djacobs comment on the same issue in @simonwhitaker's old repo here back in January too: #23. Looks like this wasn't ever officially merged in as a fix in that repo either.

@djacobs
Copy link
Owner

djacobs commented Aug 4, 2014

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.

@thetylerhayes
Copy link

@djacobs I think the answerer in https://stackoverflow.com/questions/12042932/pyapns-ssl3-write-pending-error has a pretty good summary. Does that help?

@djacobs
Copy link
Owner

djacobs commented Aug 5, 2014

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

@thetylerhayes
Copy link

What are the other tickets? (I propose we can ignore those in other repos.) I can take a stab at organizing.

@wasauce
Copy link

wasauce commented Aug 5, 2014

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

@wasauce
Copy link

wasauce commented Aug 5, 2014

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 notifications@github.com
wrote:

I have merged the fixes from #21
#21 and #25
#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
#13 (comment).

@thetylerhayes
Copy link

@dZkF9RWJT6wN8ux Any luck?

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

6 participants