Commit 51892d84 authored by Kirill Smelkov's avatar Kirill Smelkov

Stop spawned process softly on ctx cancel

In 0ad45a9c (Detect if a test leaks processes and terminate them) we
organized waiting for spawned processes with handing ctx and sending
SIGKILL to the main spawned process on ctx cancel even though other
leaked processes are always first sent with SIGTERM and - only after
shutdown timeout - later with SIGKILL.

This is too brutal. Rework the code to first send SIGTERM to the main
spawned test process too, and leverage SIGKILL only later after shutdown
timeout.

This will be tested in a later patch which exercises how cancel from
master is propagated.
parent 4fe9ee16
......@@ -269,25 +269,27 @@ def main():
if done is not None:
break
# cancel -> kill p
# cancel -> terminate p
_, _rx = select(
default, # 0
ctx.done().recv, # 1
)
if _ == 1:
p.kill()
p.terminate()
break
sleep(0.1)
# p is done - check if it leaked processes and kill them
# p should be done - check if it leaked processes and terminate/kill them
# kill p in the end if it does not stop from just SIGTERM.
while 1:
procv = session_proclist(sid=p.pid)
if len(procv) == 0:
break
for proc in procv:
emit('# leaked pid=%d %r %s' % (proc.pid, proc.name(), proc.cmdline()))
proc.terminate()
if proc.pid != p.pid:
emit('# leaked pid=%d %r %s' % (proc.pid, proc.name(), proc.cmdline()))
proc.terminate()
gone, alive = psutil.wait_procs(procv, timeout=5)
for proc in alive:
p.kill()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment