pikers / piker

(e2e) foss trading for non-tinas
GNU Affero General Public License v3.0
102 stars 17 forks source link

`binance` ws ping/pong protocol errors? #423

Closed goodboy closed 1 year ago

goodboy commented 1 year ago

Been seeing this recently while testing multichartz in #420.

No idea where it's borked but seems like binance changed something on the server end?

Attaching to pdb in crashed actor: ('brokerd.binance', 'a990ae42-605a-44da-b3e7-c978d7602e0b')

Traceback (most recent call last):
  File "/home/goodboy/repos/tractor/tractor/_runtime.py", line 196, in _invoke
    res = await coro
  File "/home/goodboy/repos/piker/piker/data/feed.py", line 246, in _setup_persistent_brokerd
    async with trio.open_nursery() as service_nursery:
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/trio/_core/_run.py", line 850, in __aexit__
    raise combined_error_from_nursery
  File "/home/goodboy/repos/piker/piker/brokers/binance.py", line 541, in stream_quotes
    async for typ, msg in msg_gen:
  File "/home/goodboy/repos/piker/piker/brokers/binance.py", line 323, in stream_messages
    await ws._connect()
  File "/home/goodboy/repos/piker/piker/data/_web_bs.py", line 74, in _connect
    await self._stack.aclose()
  File "/usr/lib/python3.10/contextlib.py", line 656, in aclose
    await self.__aexit__(None, None, None)
  File "/usr/lib/python3.10/contextlib.py", line 714, in __aexit__
    raise exc_details[1]
  File "/usr/lib/python3.10/contextlib.py", line 697, in __aexit__
    cb_suppress = await cb(*exc_details)
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/async_generator/_util.py", line 42, in __aexit__
    await self._agen.asend(None)
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/async_generator/_impl.py", line 366, in step
    return await ANextIter(self._it, start_fn, *args)
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/async_generator/_impl.py", line 202, in send
    return self._invoke(self._it.send, value)
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/async_generator/_impl.py", line 209, in _invoke
    result = fn(*args)
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/trio_websocket/_impl.py", line 105, in open_websocket
    async with trio.open_nursery() as new_nursery:
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/trio/_core/_run.py", line 850, in __aexit__
    raise combined_error_from_nursery
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/trio_websocket/_impl.py", line 1205, in _reader_task
    await handler(event)
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/trio_websocket/_impl.py", line 1145, in _handle_ping_event
    await self._send(event.response())
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/trio_websocket/_impl.py", line 1249, in _send
    data = self._wsproto.send(event)
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/wsproto/__init__.py", line 64, in send
    data += self.connection.send(event)
  File "/home/goodboy/.virtualenvs/piker310/lib/python3.10/site-packages/wsproto/connection.py", line 107, in send
    raise LocalProtocolError(
wsproto.utilities.LocalProtocolError: Event Pong(payload=bytearray(b'1668724541329')) cannot be sent in state ConnectionState.LOCAL_CLOSING.

Likely we just want an error handler block that triggers a reconnect for this?

goodboy commented 1 year ago

Pretty sure this was solved as part of #431.