Skip to content

Commit bfd906c

Browse files
committed
tm kill better timeout handling
1 parent 24190fd commit bfd906c

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

operate/services/deployment_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _get_tm_exit_url(self) -> str:
202202
def _stop_tendermint(self) -> None:
203203
"""Start tendermint process."""
204204
try:
205-
get(self._get_tm_exit_url())
205+
get(self._get_tm_exit_url(), timeout=(1, 10))
206206
time.sleep(self.SLEEP_BEFORE_TM_KILL)
207207
except Exception: # pylint: disable=broad-except
208208
print_exc()

operate/services/utils/tendermint.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def _stop_monitoring_thread(self) -> None:
309309
"""Stop a monitoring process."""
310310
if self._monitoring is not None:
311311
self._monitoring.stop() # set stop event
312-
self._monitoring.join()
312+
self._monitoring.join(timeout=20)
313313

314314
def stop(self) -> None:
315315
"""Stop a Tendermint node process."""
@@ -658,10 +658,11 @@ def run_app_in_subprocess(q: multiprocessing.Queue) -> None:
658658
def handle_server_exit() -> Response:
659659
"""Handle server exit."""
660660
app._is_on_exit = True # pylint: disable=protected-access
661-
tendermint_node.stop()
662-
663-
q.put(True)
664-
return {"node": "stopped"}
661+
try:
662+
tendermint_node.stop()
663+
finally:
664+
q.put(True)
665+
return {"node": "stopped"}
665666

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

@@ -673,9 +674,15 @@ def run_stoppable_main() -> None:
673674
p = multiprocessing.Process(target=run_app_in_subprocess, args=(q,))
674675
p.start()
675676
# wait for stop marker
676-
q.get(block=True)
677-
sleep(1)
678-
p.terminate()
677+
try:
678+
q.get(block=True)
679+
sleep(1)
680+
finally:
681+
p.terminate()
682+
with contextlib.suppress(Exception):
683+
p.join(timeout=10)
684+
p.terminate()
685+
679686

680687

681688
def main() -> None:

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@
6363
"download-binaries": "sh download_binaries.sh",
6464
"build:pearl": "sh build_pearl.sh"
6565
},
66-
"version": "0.1.0-rc196"
66+
"version": "0.1.0-rc197"
6767
}

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "olas-operate-middleware"
3-
version = "0.1.0-rc196"
3+
version = "0.1.0-rc197"
44
description = ""
55
authors = ["David Vilela <[email protected]>", "Viraj Patel <[email protected]>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)