Skip to content

Possible issue websocket logic #183

@basfroman

Description

@basfroman

Context:

When we run the test tests.e2e_tests.test_commitment.test_commitment_async then the test passes successfully.
But if we run warning logging (use the command pytest -s -vv tests/e2e_tests/test_commitment.py::test_commitment_async) then we see the following messages:

============================================================================================================================================= 1 passed in 43.54s ==============================================================================================================================================
Task was destroyed but it is pending!
task: <Task pending name='Task-18' coro=<Websocket._start_sending() running at /Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py:730> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Websocket sending exception
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/queues.py", line 158, in get
    await getter
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py", line 730, in _start_sending
    to_send_ = await self._sending.get()
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/queues.py", line 160, in get
    getter.cancel()  # Just in case getter is not done yet.
    ^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 795, in call_soon
    self._check_closed()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 541, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <coroutine object Websocket._start_sending at 0x123ad08c0>
Traceback (most recent call last):
  File "/Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py", line 746, in _start_sending
    self._received[to_send["id"]].set_exception(e)
                   ~~~~~~~^^^^^^
TypeError: string indices must be integers, not 'str'
Exception ignored in: <coroutine object Queue.get at 0x1683b9c40>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/queues.py", line 160, in get
    getter.cancel()  # Just in case getter is not done yet.
    ^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 795, in call_soon
    self._check_closed()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 541, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name='Task-37' coro=<Websocket._start_sending() running at /Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py:730> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-25' coro=<Websocket._start_sending() running at /Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py:730> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Websocket sending exception
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/queues.py", line 158, in get
    await getter
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py", line 730, in _start_sending
    to_send_ = await self._sending.get()
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/queues.py", line 160, in get
    getter.cancel()  # Just in case getter is not done yet.
    ^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 795, in call_soon
    self._check_closed()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 541, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <coroutine object Websocket._start_sending at 0x123ad07b0>
Traceback (most recent call last):
  File "/Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py", line 746, in _start_sending
    self._received[to_send["id"]].set_exception(e)
                   ~~~~~~~^^^^^^
TypeError: string indices must be integers, not 'str'
Task was destroyed but it is pending!
task: <Task pending name='Task-29' coro=<Websocket._start_sending() running at /Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py:730> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Websocket sending exception
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/queues.py", line 158, in get
    await getter
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py", line 730, in _start_sending
    to_send_ = await self._sending.get()
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/queues.py", line 160, in get
    getter.cancel()  # Just in case getter is not done yet.
    ^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 795, in call_soon
    self._check_closed()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 541, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <coroutine object Websocket._start_sending at 0x123ad0480>
Traceback (most recent call last):
  File "/Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py", line 746, in _start_sending
    self._received[to_send["id"]].set_exception(e)
                   ~~~~~~~^^^^^^
TypeError: string indices must be integers, not 'str'
Task was destroyed but it is pending!
task: <Task pending name='Task-33' coro=<Websocket._start_sending() running at /Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py:730> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Websocket sending exception
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/queues.py", line 158, in get
    await getter
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py", line 730, in _start_sending
    to_send_ = await self._sending.get()
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/queues.py", line 160, in get
    getter.cancel()  # Just in case getter is not done yet.
    ^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 795, in call_soon
    self._check_closed()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 541, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <coroutine object Websocket._start_sending at 0x123ad0260>
Traceback (most recent call last):
  File "/Users/roman/Python/bittensor_sdk/venv/lib/python3.12/site-packages/async_substrate_interface/async_substrate.py", line 746, in _start_sending
    self._received[to_send["id"]].set_exception(e)
                   ~~~~~~~^^^^^^
TypeError: string indices must be integers, not 'str'

Additional context:

I tried:

  1. Running the test with and without async with async_subtensor as sub:
  2. Manually running the test in await async_subtensor.initialize() and await async_subtensor.close()
    Always the same result.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions