Commit 06a67084 authored by Florian Fischer's avatar Florian Fischer
Browse files

[eval.py] fix killing a server not properly terminating

parent d5b51805
...@@ -367,7 +367,7 @@ TERMINATION_TIME = 10 ...@@ -367,7 +367,7 @@ TERMINATION_TIME = 10
CLIENT_SEPARATION_TIME = 10 CLIENT_SEPARATION_TIME = 10
TERMINATION_CMD = 'nc {host} 12345' TERMINATION_CMD = 'nc {host} 12345'
SERVER_KILL_CMD = 'pkill -9 {proc}' SERVER_KILL_CMD = 'pkill -9 -f {proc}'
def write_desc(data_dir): def write_desc(data_dir):
...@@ -582,40 +582,39 @@ def prepare_emper_flavors(flavors): ...@@ -582,40 +582,39 @@ def prepare_emper_flavors(flavors):
build_env=desc.get('build_env', {})) build_env=desc.get('build_env', {}))
def shutdown_server(server: subprocess.Popen): def shutdown_server(server: str, proc: subprocess.Popen):
"""Terminate a running sever command""" """Terminate a running sever command"""
# server is not running # server is not running
if server.poll() is not None: if proc.poll() is not None:
return return
termination_cmd = TERMINATION_CMD.format(host=HOST) termination_cmd = TERMINATION_CMD.format(host=HOST)
# try to shutdown by sending "quit" to the server # try to shutdown by sending "quit" to the server
try: try:
subprocess.run(termination_cmd.split(), input=b'quit\n', check=True) subprocess.run(termination_cmd.split(),
input=b'quit\n',
check=True,
timeout=TERMINATION_TIME)
# wait for the server to terminate
proc.wait(TERMINATION_TIME)
return
except subprocess.CalledProcessError as run_err: except subprocess.CalledProcessError as run_err:
log.warning('%s terminated unsuccessful: %s', termination_cmd, run_err) log.warning('%s terminated unsuccessful: %s', termination_cmd, run_err)
# wait for the server to terminate except subprocess.TimeoutExpired as timeout_err:
try: log.warning('%s termination timeout: %s', termination_cmd, timeout_err)
server.wait(TERMINATION_TIME)
return
except subprocess.TimeoutExpired:
pass
# kill the server using pkill(1) -9 # kill the server using pkill(1) -9
kill_cmd = '' kill_cmd = ''
if REMOTE_CMD: if REMOTE_CMD:
kill_cmd += REMOTE_CMD.format(host=HOST, ssh_port=SSH_PORT) + ' ' kill_cmd += REMOTE_CMD.format(host=HOST, ssh_port=SSH_PORT) + ' '
if isinstance(server.args, list): server_bin = SERVER_CMDS[server].split()[0]
server_bin = server.args[0]
elif isinstance(server.args, str):
server_bin = server.args.split()[0]
kill_cmd += SERVER_KILL_CMD.format(proc=server_bin) kill_cmd += SERVER_KILL_CMD.format(proc=server_bin)
cmd_run(kill_cmd, check=False) cmd_run(kill_cmd, check=False)
server.wait(TERMINATION_TIME) proc.wait(TERMINATION_TIME)
class BenchResult(Enum): class BenchResult(Enum):
...@@ -784,7 +783,7 @@ def bench() -> Dict[str, List[List[BenchResult]]]: ...@@ -784,7 +783,7 @@ def bench() -> Dict[str, List[List[BenchResult]]]:
sleep(CLIENT_SEPARATION_TIME) sleep(CLIENT_SEPARATION_TIME)
shutdown_server(server_popen) shutdown_server(server, server_popen)
return results return results
......
Supports Markdown
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