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
678 stars 166 forks source link

asyncio.exceptions.TimeoutError && AttributeError: 'NoneType' object has no attribute 'resume_reading' #213

Closed dima-dmytruk23 closed 2 years ago

dima-dmytruk23 commented 2 years ago

Hi. We are using Python3.8, websocket-client==1.1.1, websockets==9.1, unicorn-binance-websocket-api==1.31.0

We receive about 600 data objects every 250 ms.

The specifics of our service: Every 50 minutes we close the old websocket and open a new websocket. Maybe we are doing it incorrectly?

I have following error

Exception in thread Thread-400:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/threading.py", line 69, in run
    reraise(*_capture_exception())
  File "/usr/local/lib/python3.8/site-packages/sentry_sdk/_compat.py", line 54, in reraise
    raise value
  File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/threading.py", line 67, in run
    return old_run_func(self, *a, **kw)
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.8/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_manager.py", line 473, in _create_stream_thread
    loop.run_until_complete(socket.start_socket())
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.8/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_socket.py", line 63, in start_socket
    async with BinanceWebSocketApiConnection(self.manager,
  File "/usr/local/lib/python3.8/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_connection.py", line 147, in __aenter__
    self.manager.websocket_list[self.stream_id] = await self._conn.__aenter__()
  File "/usr/local/lib/python3.8/site-packages/websockets/legacy/client.py", line 632, in __aenter__
    return await self
  File "/usr/local/lib/python3.8/site-packages/websockets/legacy/client.py", line 649, in __await_impl_timeout__
    return await asyncio.wait_for(self.__await_impl__(), self.open_timeout)
  File "/usr/local/lib/python3.8/asyncio/tasks.py", line 501, in wait_for
    raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError
CRITICAL:root:BinanceWebSocketApiSocket.start_socket(ba8e6775-d709-45ea-9154-d1be2facac61, {'kline_1M', 'kline_1h', 'kline_1d', 'kline_4h', 'kline_1w'}, ['trbusdt', 'iostusdt', 'c98usdt', 'dgbusdt', 'balusdt', 'sklusdt', 'btcdomusdt', 'xlmusdt', 'ankrusdt', 'rayusdt', 'etcusdt', 'manausdt', 'dodousdt', 'fttbusd', 'bakeusdt', 'zenusdt', 'hbarusdt', 'btcbusd', 'renusdt', 'dogeusdt', 'grtusdt', 'bchusdt', 'dashusdt', 'icxusdt', 'akrousdt', 'srmusdt', 'omgusdt', 'ethusdt', 'xrpbusd', 'xrpusdt', 'btcusdt', 'algousdt', 'ltcusdt', 'chrusdt', 'rvnusdt', 'avaxusdt', 'nknusdt', 'linkusdt', 'kavausdt', 'eosusdt']) - Exception ConnectionClosed - error_msg: sent 1011 (unexpected error) keepalive ping timeout; no close frame received
CRITICAL:root:BinanceWebSocketApiManager.stream_is_crashing(ba8e6775-d709-45ea-9154-d1be2facac61)
ERROR:websockets.client:data transfer failed
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/websockets/legacy/protocol.py", line 944, in transfer_data
    message = await self.read_message()
  File "/usr/local/lib/python3.8/site-packages/websockets/legacy/protocol.py", line 1013, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "/usr/local/lib/python3.8/site-packages/websockets/legacy/protocol.py", line 1089, in read_data_frame
    frame = await self.read_frame(max_size)
  File "/usr/local/lib/python3.8/site-packages/websockets/legacy/protocol.py", line 1144, in read_frame
    frame = await Frame.read(
  File "/usr/local/lib/python3.8/site-packages/websockets/legacy/framing.py", line 100, in read
    data = await reader(length)
  File "/usr/local/lib/python3.8/asyncio/streams.py", line 731, in readexactly
    self._maybe_resume_transport()
  File "/usr/local/lib/python3.8/asyncio/streams.py", line 461, in _maybe_resume_transport
    self._transport.resume_reading()
  File "/usr/local/lib/python3.8/asyncio/sslproto.py", line 344, in resume_reading
    self._ssl_protocol._transport.resume_reading()
AttributeError: 'NoneType' object has no attribute 'resume_reading'

Any ideas, suggestions, why this is happening?

dima-dmytruk23 commented 2 years ago

Apparently this error (timeoutError) occurs when replace_stream

oliver-zehentleitner commented 2 years ago

I need full logfile and answers for asked questions like stream_buffer or callback, ...

oliver-zehentleitner commented 2 years ago

Without a code example and logfiles and cant help you.

But it seems this error is related to this issue: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/issues/221

In release 1.35.0 a fix for this will be included.