Comment hard-kill-sidestep for now since nursery version covers it?

transport_hardening
Tyler Goodlet 2021-06-30 08:44:28 -04:00
parent 6d72a4ef45
commit 2556a568e7
1 changed files with 33 additions and 30 deletions

View File

@ -157,6 +157,7 @@ async def cancel_on_completion(
async def do_hard_kill( async def do_hard_kill(
proc: trio.Process, proc: trio.Process,
) -> None: ) -> None:
# NOTE: this timeout used to do nothing since we were shielding # NOTE: this timeout used to do nothing since we were shielding
# the ``.wait()`` inside ``new_proc()`` which will pretty much # the ``.wait()`` inside ``new_proc()`` which will pretty much
@ -209,44 +210,46 @@ async def spawn_subactor(
yield proc yield proc
finally: finally:
log.debug(f"Attempting to kill {proc}") log.runtime(f"Attempting to kill {proc}")
# XXX: do this **after** cancellation/tearfown # XXX: do this **after** cancellation/tearfown
# to avoid killing the process too early # to avoid killing the process too early
# since trio does this internally on ``__aexit__()`` # since trio does this internally on ``__aexit__()``
if ( # if (
is_root_process() # is_root_process()
# XXX: basically the pre-closing of stdstreams in a # # XXX: basically the pre-closing of stdstreams in a
# root-processe's ``trio.Process.aclose()`` can clobber # # root-processe's ``trio.Process.aclose()`` can clobber
# any existing debugger session so we avoid # # any existing debugger session so we avoid
and _runtime_vars['_debug_mode'] # and _runtime_vars['_debug_mode']
and _global_actor_in_debug is not None # and _global_actor_in_debug is not None
): # ):
# XXX: this is ``trio.Process.aclose()`` MINUS the # # XXX: this is ``trio.Process.aclose()`` MINUS the
# std-streams pre-closing steps inside ``proc.__aexit__()`` # # std-streams pre-closing steps inside ``proc.__aexit__()``
# (see below) which incluses a ``Process.kill()`` call # # (see below) which incluses a ``Process.kill()`` call
log.critical( # log.error(
"Root process tty is locked in debug mode by " # "Root process tty is locked in debug mode by "
f"{_global_actor_in_debug}. If the console is hanging, you " # f"{_global_actor_in_debug}. If the console is hanging, you "
"may need to trigger a KBI to kill any " # "may need to trigger a KBI to kill any "
"not-fully-initialized" " subprocesses and allow errors " # "not-fully-initialized" " subprocesses and allow errors "
"from `trio` to propagate" # "from `trio` to propagate"
) # )
try: # try:
# one more graceful wait try can can be cancelled by KBI # # one more graceful wait try can can be cancelled by KBI
# sent by user. # # sent by user.
await proc.wait() # await proc.wait()
finally: # finally:
if proc.returncode is None: # if proc.returncode is None:
# with trio.CancelScope(shield=True): # # with trio.CancelScope(shield=True):
await do_hard_kill(proc) # # await proc.wait()
else:
# with trio.CancelScope(shield=True): # await do_hard_kill(proc)
await do_hard_kill(proc) # else:
await do_hard_kill(proc)
async def new_proc( async def new_proc(