LUCIT-Systems-and-Development / unicorn-binance-websocket-api

A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.
https://unicorn-binance-websocket-api.docs.lucit.tech/
Other
680 stars 165 forks source link

InvalidStateError #110

Closed oliver-zehentleitner closed 3 years ago

oliver-zehentleitner commented 3 years ago

Related to issue https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/issues/18, https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/issues/105, https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/issues/83

The first issue https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/issues/18 was created in Jun 2019 by @DaWe35 who reported this error:

Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/.local/lib/python3.6/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_manager.py", line 142, in _create_stream_thread
    loop.run_until_complete(binance_websocket_api_socket.start_socket())
  File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
    return future.result()
  File "/home/user/.local/lib/python3.6/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_socket.py", line 62, in start_socket
    received_stream_data_json = await websocket.receive()
  File "/home/user/.local/lib/python3.6/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_connection.py", line 183, in receive
    received_data = await self.handler_binance_websocket_api_manager.websocket_list[self.stream_id].recv()
  File "/home/user/.local/lib/python3.6/site-packages/websockets/protocol.py", line 441, in recv
    self._put_message_waiter.set_result(None)
asyncio.base_futures.InvalidStateError: invalid state

We added an error handling for asyncio.base_futures.InvalidStateError: invalid state and a restart process for the stream and it worked well for a while.

In Nov 2019 the websockets 8.1 was released and we switched over to it as a requirement, we are using newer python versions and it looks like, that something important has changed.

So I think its the best to remove that code part and lets see whats happens then..

If someone is receiving a new InvalidStateError please post

  1. websockets version
  2. python version
  3. OS
  4. stream_buffer or process_stream_data

in this issue below!

oliver-zehentleitner commented 3 years ago

Please update to 1.17.4 and start testing!

oliver-zehentleitner commented 3 years ago

Looks good till now :)

We can reopen if needed!