Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subscriber not properly unsubscribing when an exception is raised inside the context manager #112

Merged

Conversation

jolorke
Copy link
Contributor

@jolorke jolorke commented Apr 3, 2024

Turned out to be a duplicate of this:
#58

But this one also contains testcases :)

jolorke added 2 commits April 3, 2024 17:19
…associated queue from the channel in case of a raised exception inside the context manager (e.g. being used inside a generator that gets closed raising GeneratorExit)
@jolorke jolorke force-pushed the fix/unsubscribe_not_deleting_queue branch from 5630017 to 3015fff Compare April 3, 2024 15:20
@alex-oleshkevich alex-oleshkevich self-requested a review April 3, 2024 15:57
@alex-oleshkevich
Copy link
Member

I get this exception when running pytest.
Python 3.11.8

Exception ignored in: <coroutine object Broadcast._listener at 0x7363387bac50>
Traceback (most recent call last):
  File "/home/alex/projects/broadcaster/broadcaster/_base.py", line 74, in _listener
    event = await self._backend.next_published()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/projects/broadcaster/broadcaster/_backends/memory.py", line 30, in next_published
    event = await self._published.get()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/queues.py", line 160, in get
    getter.cancel()  # Just in case getter is not done yet.
    ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 762, in call_soon
    self._check_closed()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 520, 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-11' coro=<Broadcast._listener() done, defined at /home/alex/projects/broadcaster/broadcaster/_base.py:72> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object Broadcast._listener at 0x7363387bb3d0>
Traceback (most recent call last):
  File "/home/alex/projects/broadcaster/broadcaster/_base.py", line 74, in _listener
    event = await self._backend.next_published()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/projects/broadcaster/broadcaster/_backends/memory.py", line 30, in next_published
    event = await self._published.get()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/queues.py", line 160, in get
    getter.cancel()  # Just in case getter is not done yet.
    ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 762, in call_soon
    self._check_closed()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 520, 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-13' coro=<Broadcast._listener() done, defined at /home/alex/projects/broadcaster/broadcaster/_base.py:72> wait_for=<Future cancelled>>

@jolorke
Copy link
Contributor Author

jolorke commented Apr 4, 2024

Thanks!

@jolorke jolorke deleted the fix/unsubscribe_not_deleting_queue branch April 4, 2024 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants