HENNGE / aapns

Asynchronous Apple Push Notifications
https://aapns.readthedocs.io/en/latest/
Other
13 stars 2 forks source link

rewrite timeout/reconnect logic #3

Closed ojii closed 7 years ago

freedomofkeima commented 7 years ago

Now:

ERROR:asyncio:Fatal read error on socket transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x10f957a20>
transport: <_SelectorSocketTransport fd=13 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/selector_events.py", line 724, in _read_ready
    data = self._sock.recv(self.max_size)
TimeoutError: [Errno 60] Operation timed out

Before:

ERROR:asyncio:Exception in callback _SelectorSocketTransport._read_ready()
handle: <Handle _SelectorSocketTransport._read_ready()>
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 127, in _run
    self._callback(*self._args)
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/selector_events.py", line 731, in _read_ready
    self._protocol.data_received(data)
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py", line 516, in data_received
    self._app_protocol.data_received(chunk)
  File "/Users/iskandarsetiadi/Documents/shobosso-unreadchecker/venv/lib/python3.6/site-packages/aapns-1.0.0.dev7-py3.6.egg/aapns/connection.py", line 114, in data_received
    self.end_stream(event.stream_id)
  File "/Users/iskandarsetiadi/Documents/shobosso-unreadchecker/venv/lib/python3.6/site-packages/aapns-1.0.0.dev7-py3.6.egg/aapns/connection.py", line 156, in end_stream
    response.future.set_result(True)
asyncio.base_futures.InvalidStateError: invalid state

But I still cannot reproduce the infinite broken state after InvalidStateError exception 🤔 The next push notification still works properly

ojii commented 7 years ago

Now:

Does it auto-reconnect after that error?

freedomofkeima commented 7 years ago

I tried TimeoutError case and both are working properly after that error.

freedomofkeima commented 7 years ago

Okay, now I can reproduce the old problem. If there's concurrent connections, the old one will not auto-reconnect:

ERROR:tornado.access:500 POST /push_message (127.0.0.1) 60000.75ms
ERROR:asyncio:Fatal read error on socket transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x10d1f0748>
transport: <_SelectorSocketTransport fd=9 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/selector_events.py", line 724, in _read_ready
    data = self._sock.recv(self.max_size)
TimeoutError: [Errno 60] Operation timed out
ERROR:asyncio:Exception in callback APNSProtocol.connection_lost(TimeoutError(...on timed out'))
handle: <Handle APNSProtocol.connection_lost(TimeoutError(...on timed out'))>
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 127, in _run
    self._callback(*self._args)
  File "/Users/iskandarsetiadi/Documents/shobosso-unreadchecker/venv/lib/python3.6/site-packages/aapns-1.0.0.dev7-py3.6.egg/aapns/connection.py", line 101, in connection_lost
    pending.future.set_exception(Disconnected())
asyncio.base_futures.InvalidStateError: invalid state
WARNING:root:[AAPNS] Timeout Error sending ios push
ERROR:tornado.access:500 POST /push_message (127.0.0.1) 60002.98ms
WARNING:root:[AAPNS] Timeout Error sending ios push
ERROR:tornado.access:500 POST /push_message (127.0.0.1) 59999.83ms

The new one looks good:

ERROR:tornado.access:500 POST /push_message (127.0.0.1) 60002.84ms
ERROR:asyncio:Fatal read error on socket transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x10e311f28>
transport: <_SelectorSocketTransport fd=13 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/selector_events.py", line 724, in _read_ready
    data = self._sock.recv(self.max_size)
TimeoutError: [Errno 60] Operation timed out
WARNING:root:[AAPNS] Disconnected: 
ERROR:tornado.access:500 POST /push_message (127.0.0.1) 66650.01ms
INFO:root:[HSBP] Pushed Notification to iOS, ...
INFO:tornado.access:200 POST /push_message (127.0.0.1) 600.80ms