From 77fc705b1f0f3840683b95488cbb06f4ad3065bc Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 29 Nov 2021 22:52:19 -0500 Subject: [PATCH] Add nooz --- newsfragments/266.bug.rst | 12 ++++++++++++ tractor/_spawn.py | 10 +++++----- 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 newsfragments/266.bug.rst diff --git a/newsfragments/266.bug.rst b/newsfragments/266.bug.rst new file mode 100644 index 0000000..a246baf --- /dev/null +++ b/newsfragments/266.bug.rst @@ -0,0 +1,12 @@ +Fix graceful cancellation of daemon actors + +Previously, his was a bug where if the soft wait on a sub-process (the +``await .proc.wait()``) in the reaper task teardown was cancelled we +would fail over to the hard reaping sequence (meant for culling off any +potential zombies via system kill signals). The hard reap has a timeout +of 3s (currently though in theory we could make it shorter?) before +system signalling kicks in. This means that any daemon actor still +running during nursery exit would get hard reaped (3s later) instead of +cancelled via IPC message. Now we catch the ``trio.Cancelled``, call +``Portal.cancel_actor()`` on the daemon and expect the child to +self-terminate after the runtime cancels and shuts down the process. diff --git a/tractor/_spawn.py b/tractor/_spawn.py index 4fb05d7..6ede566 100644 --- a/tractor/_spawn.py +++ b/tractor/_spawn.py @@ -298,11 +298,11 @@ async def new_proc( try: await proc.wait() except trio.Cancelled: - # if cancelled during a soft wait cancel the child - # actor before entering the hard reap - # sequence below. This means we try to do a - # graceful teardown before getting out zombie - # killing tools. + # if cancelled during a soft wait, cancel the child + # actor before entering the hard reap sequence + # below. This means we try to do a graceful teardown + # via sending a cancel message before getting out + # zombie killing tools. with trio.CancelScope(shield=True): await portal.cancel_actor() raise