Skip to content

Commit

Permalink
tm kill better timeout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
solarw committed Nov 13, 2024
1 parent 24190fd commit bfd906c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion operate/services/deployment_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _get_tm_exit_url(self) -> str:
def _stop_tendermint(self) -> None:
"""Start tendermint process."""
try:
get(self._get_tm_exit_url())
get(self._get_tm_exit_url(), timeout=(1, 10))
time.sleep(self.SLEEP_BEFORE_TM_KILL)
except Exception: # pylint: disable=broad-except
print_exc()
Expand Down
23 changes: 15 additions & 8 deletions operate/services/utils/tendermint.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def _stop_monitoring_thread(self) -> None:
"""Stop a monitoring process."""
if self._monitoring is not None:
self._monitoring.stop() # set stop event
self._monitoring.join()
self._monitoring.join(timeout=20)

def stop(self) -> None:
"""Stop a Tendermint node process."""
Expand Down Expand Up @@ -658,10 +658,11 @@ def run_app_in_subprocess(q: multiprocessing.Queue) -> None:
def handle_server_exit() -> Response:
"""Handle server exit."""
app._is_on_exit = True # pylint: disable=protected-access
tendermint_node.stop()

q.put(True)
return {"node": "stopped"}
try:
tendermint_node.stop()
finally:
q.put(True)
return {"node": "stopped"}

app.run(host="localhost", port=8080)

Expand All @@ -673,9 +674,15 @@ def run_stoppable_main() -> None:
p = multiprocessing.Process(target=run_app_in_subprocess, args=(q,))
p.start()
# wait for stop marker
q.get(block=True)
sleep(1)
p.terminate()
try:
q.get(block=True)
sleep(1)
finally:
p.terminate()
with contextlib.suppress(Exception):
p.join(timeout=10)
p.terminate()



def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@
"download-binaries": "sh download_binaries.sh",
"build:pearl": "sh build_pearl.sh"
},
"version": "0.1.0-rc196"
"version": "0.1.0-rc197"
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "olas-operate-middleware"
version = "0.1.0-rc196"
version = "0.1.0-rc197"
description = ""
authors = ["David Vilela <[email protected]>", "Viraj Patel <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit bfd906c

Please sign in to comment.