Skip to content

Nursery does not re-raise error from .run_in_actor() remote task #287

Description

@didimelli

Hello,
I am on WSL2, with python 3.9.9 and tractor 0.1.0a4.

I am testing the cancellation of the tasks when one raises. I am using this simple snippet:

import tractor
import trio
from trio import sleep
from trio import sleep_forever

async def not_raising() -> None:
    print("inside not raising")
    await sleep_forever()

async def raising() -> None:
    print("inside raising!")
    await sleep(5)
    raise ValueError("random raise from bad task")

async def main() -> None:
    async with tractor.open_nursery() as n:
        t1 = await n.run_in_actor(not_raising, name="raising")
        t2 = await n.run_in_actor(raising, name="not raising")
    print("outside the tractor nursery")

async def main2() -> None:
    async with trio.open_nursery() as n:
        n.start_soon(not_raising)
        n.start_soon(raising)
    print("outside trio nursery")

if __name__ == "__main__":
    trio.run(main)

I would expect that when raising task raises ValueError, the other task gets cancelled (as Trio does, as in main2 function). However, when I run this code, i get:

No actor could be found @ 127.0.0.1:1616
inside not raising
inside raising!
Jan 03 16:03:58 (not raising, 11045, raising)) [ERROR] tractor _actor.py:260 Actor crashed:
Traceback (most recent call last):
  File "/home/didi/leaf/leaf-radio/.venv/lib/python3.9/site-packages/tractor/_actor.py", line 232, in _invoke
    await chan.send({'return': await coro, 'cid': cid})
  File "/home/didi/leaf/leaf-radio/gse/main.py", line 27, in raising
    raise ValueError("random raise from bad task")
ValueError: random raise from bad task
Remote context error for ('not raising', '8e3309a2-2e39-4a8e-a3ec-15ce0977c1a8'):244eb763-1b98-4f46-9d09-93aa6791e400:
Traceback (most recent call last):
  File "/home/didi/leaf/leaf-radio/.venv/lib/python3.9/site-packages/tractor/_actor.py", line 232, in _invoke
    await chan.send({'return': await coro, 'cid': cid})
  File "/home/didi/leaf/leaf-radio/gse/main.py", line 27, in raising
    raise ValueError("random raise from bad task")
ValueError: random raise from bad task

Cancelling ('not raising', '8e3309a2-2e39-4a8e-a3ec-15ce0977c1a8') after error ('not raising', '8e3309a2-2e39-4a8e-a3ec-15ce0977c1a8')
Traceback (most recent call last):
  File "/home/didi/leaf/leaf-radio/.venv/lib/python3.9/site-packages/tractor/_actor.py", line 232, in _invoke
    await chan.send({'return': await coro, 'cid': cid})
  File "/home/didi/leaf/leaf-radio/gse/main.py", line 27, in raising
    raise ValueError("random raise from bad task")
ValueError: random raise from bad task

Cancelling existing result waiter task for ('not raising', '8e3309a2-2e39-4a8e-a3ec-15ce0977c1a8')

and the programs hangs indefinitely. I need to press ctrl+c to kill the process.

The traceback shows that tractor is trying to cancel the not_raising task (Cancelling ('not raising', '8e3309a2-2e39-4a8e-a3ec-15ce0977c1a8') after error ('not raising', '8e3309a2-2e39-4a8e-a3ec-15ce0977c1a8')), but the program hangs there.

If instead of sleep_forever(), i use sleep(20), the program actually sleeps for 20 seconds before exiting.

Since this is a basic feature of the library, i feel like i am missing something.
Could you please help me understand what it is happening?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcancellationSC teardown semantics and anti-zombie semanticssupervision

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions