Skip to content

Dropped exceptions in as_safe_channel #3333

@A5rocks

Description

@A5rocks
async def test8() -> None:
    @trio.as_safe_channel
    async def agen():
        await chan.aclose()
        raise ValueError()
        yield

    async with agen() as chan:
        async for _ in chan:
            pass

This sometimes raises this:

Traceback (most recent call last):
  File "C:\Users\A5rocks\Documents\trio\repro.py", line 124, in <module>
    trio.run(test8)
    ~~~~~~~~^^^^^^^
  File "C:\Users\A5rocks\Documents\trio\src\trio\_core\_run.py", line 2547, in run
    raise runner.main_task_outcome.error
  File "C:\Users\A5rocks\Documents\trio\repro.py", line 121, in test8
    async for _ in chan:
        pass
  File "C:\Users\A5rocks\Documents\trio\src\trio\_abc.py", line 689, in __anext__
    return await self.receive()
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\A5rocks\Documents\trio\src\trio\_channel.py", line 477, in receive
    return await self._recv_chan.receive()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\A5rocks\Documents\trio\src\trio\_channel.py", line 385, in receive
    return await trio.lowlevel.wait_task_rescheduled(abort_fn)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\A5rocks\Documents\trio\src\trio\_core\_traps.py", line 208, in wait_task_rescheduled
    return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\A5rocks\Documents\trio\.venv\Lib\site-packages\outcome\_impl.py", line 213, in unwrap
    raise captured_error
trio.ClosedResourceError

Notice no ValueError! Spun off of #3331

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions