python-trio / trio-asyncio

a re-implementation of the asyncio mainloop on top of Trio
Other
188 stars 37 forks source link

Intermittent test_cancel_loop failure #95

Closed shamrin closed 3 years ago

shamrin commented 3 years ago

While preparing for 0.12.0 release (PR #94), I've noticed intermittent test_cancel_loop failure. I've temporarily disabled the test with xfail to make CI green: d0bc23e1ac68fda66f6848ecd6efeec60eb85683, 9a9f357a272b5ea2c7c13b1f9d5d2ebeeddcf966. But it would be nice to figure out why it happens. I've checked May 2020 commit, failure is there too.

Possibly related:

$ pytest tests/test_misc.py --runxfail

================================================================================= test session starts =================================================================================
platform darwin -- Python 3.9.0, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: /Users/asha/src/trio-asyncio/tests, configfile: pytest.ini
plugins: cov-2.10.1, trio-0.7.0
collected 17 items                                                                                                                                                                    

tests/test_misc.py .............F...

====================================================================================== FAILURES =======================================================================================
_______________________________________________________________________________ test_cancel_loop[True] ________________________________________________________________________________
trio.MultiError: Cancelled(), ValueError('hi'), Cancelled()

Details of embedded exception 1:

  Traceback (most recent call last):
    File "/Users/asha/src/trio-asyncio/trio_asyncio/_handles.py", line 109, in _run
      res = await self._callback(*self._args)
    File "/Users/asha/src/trio-asyncio/tests/test_misc.py", line 260, in trio_task
      raise ValueError("hi")
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py", line 815, in __aexit__
      raise combined_error_from_nursery
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_timeouts.py", line 40, in sleep_forever
      await trio.lowlevel.wait_task_rescheduled(lambda _: trio.lowlevel.Abort.SUCCEEDED)
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_traps.py", line 166, in wait_task_rescheduled
      return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/outcome/_impl.py", line 138, in unwrap
      raise captured_error
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py", line 1167, in raise_cancel
      raise Cancelled._create()
  trio.Cancelled: Cancelled

Details of embedded exception 2:

  Traceback (most recent call last):
    File "/Users/asha/src/trio-asyncio/tests/test_misc.py", line 254, in trio_task
      await trio.sleep_forever()
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_timeouts.py", line 40, in sleep_forever
      await trio.lowlevel.wait_task_rescheduled(lambda _: trio.lowlevel.Abort.SUCCEEDED)
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_traps.py", line 166, in wait_task_rescheduled
      return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/outcome/_impl.py", line 138, in unwrap
      raise captured_error
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py", line 1167, in raise_cancel
      raise Cancelled._create()
  trio.Cancelled: Cancelled

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/Users/asha/src/trio-asyncio/trio_asyncio/_handles.py", line 109, in _run
      res = await self._callback(*self._args)
    File "/Users/asha/src/trio-asyncio/tests/test_misc.py", line 260, in trio_task
      raise ValueError("hi")
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py", line 815, in __aexit__
      raise combined_error_from_nursery
    File "/Users/asha/src/trio-asyncio/tests/test_misc.py", line 260, in trio_task
      raise ValueError("hi")
  ValueError: hi

Details of embedded exception 3:

  Traceback (most recent call last):
    File "/Users/asha/src/trio-asyncio/tests/test_misc.py", line 254, in trio_task
      await trio.sleep_forever()
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_timeouts.py", line 40, in sleep_forever
      await trio.lowlevel.wait_task_rescheduled(lambda _: trio.lowlevel.Abort.SUCCEEDED)
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_traps.py", line 166, in wait_task_rescheduled
      return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/outcome/_impl.py", line 138, in unwrap
      raise captured_error
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py", line 1167, in raise_cancel
      raise Cancelled._create()
  trio.Cancelled: Cancelled

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/Users/asha/src/trio-asyncio/trio_asyncio/_handles.py", line 109, in _run
      res = await self._callback(*self._args)
    File "/Users/asha/src/trio-asyncio/tests/test_misc.py", line 260, in trio_task
      raise ValueError("hi")
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py", line 815, in __aexit__
      raise combined_error_from_nursery
    File "/Users/asha/src/trio-asyncio/tests/test_misc.py", line 260, in trio_task
      raise ValueError("hi")
  ValueError: hi

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/Users/asha/src/trio-asyncio/trio_asyncio/_handles.py", line 109, in _run
      res = await self._callback(*self._args)
    File "/Users/asha/src/trio-asyncio/tests/test_misc.py", line 260, in trio_task
      raise ValueError("hi")
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py", line 815, in __aexit__
      raise combined_error_from_nursery
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py", line 933, in _nested_child_finished
      await checkpoint()
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py", line 2321, in checkpoint
      await _core.wait_task_rescheduled(lambda _: _core.Abort.SUCCEEDED)
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_traps.py", line 166, in wait_task_rescheduled
      return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/outcome/_impl.py", line 138, in unwrap
      raise captured_error
    File "/Users/asha/Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py", line 1167, in raise_cancel
      raise Cancelled._create()
  trio.Cancelled: Cancelled

During handling of the above exception, another exception occurred:

value = <trio.Nursery object at 0x106c8eca0>

    async def yield_(value=None):
>       return await _yield_(value)

../../Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/async_generator/_impl.py:106: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/async_generator/_impl.py:99: in _yield_
    return (yield _wrap(value))
tests/test_misc.py:266: in test_cancel_loop
    scope.cancel()
../../Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py:815: in __aexit__
    raise combined_error_from_nursery
tests/test_misc.py:244: in manage_loop
    await trio.sleep_forever()
../../Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_ki.py:159: in wrapper
    return fn(*args, **kwargs)
../../Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py:549: in __exit__
    raise remaining_error_after_cancel_scope
tests/test_misc.py:244: in manage_loop
    await trio.sleep_forever()
/usr/local/Cellar/python@3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py:193: in __aexit__
    await self.gen.athrow(typ, value, traceback)
trio_asyncio/_loop.py:406: in open_loop
    current_loop.reset(old_loop)
../../Library/Caches/pypoetry/virtualenvs/trio-asyncio-7FvA6rDn-py3.9/lib/python3.9/site-packages/trio/_core/_run.py:815: in __aexit__
    raise combined_error_from_nursery
trio_asyncio/_handles.py:135: in _run
    self._fut.set_exception(rest)
trio_asyncio/_base.py:313: in call_soon
    return self._queue_handle(asyncio.Handle(callback, args, self, **context))
trio_asyncio/_async.py:13: in _queue_handle
    self._check_closed()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <TrioEventLoop running=closed at 0x106c8e1f0>

    def _check_closed(self):
        if self._closed:
>           raise RuntimeError('Event loop is closed')
E           RuntimeError: Event loop is closed

/usr/local/Cellar/python@3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py:510: RuntimeError
=============================================================================== short test summary info ===============================================================================
FAILED tests/test_misc.py::test_cancel_loop[True] - RuntimeError: Event loop is closed
============================================================================ 1 failed, 16 passed in 1.09s =============================================================================