Skip to content

Commit 22abb1c

Browse files
committed
Catch Timeout exception when stopping endpoints instead of printing
stack trace [sc-45767]
1 parent 1e6463b commit 22abb1c

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
hooks:
2323
- id: ruff-check
2424
types_or: [ python ]
25-
args: [ --select, I ]
25+
args: [ --fix, --select, I ]
2626
- id: ruff-check
2727
types_or: [ python ]
2828
args: [ --fix, --select, I ]

README.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,3 @@ Documentation
5555
=============
5656

5757
Complete documentation for Globus Compute is available `here <https://globus-compute.readthedocs.io>`_
58-
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Bug Fixes
2+
^^^^^^^^^
3+
4+
- When force deleting an endpoint, a Timeout exception may be raised when waiting for the parent
5+
Endpoint process to terminate. This is not user-friendly, the stacktrace is now replaced with
6+
a more readable message to repeat the deletion command.

compute_endpoint/globus_compute_endpoint/endpoint/endpoint.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,14 @@ def stop_endpoint(
661661

662662
# Give parent process chance to clean itself up
663663
parent.terminate()
664-
parent.wait(timeout=grace_period_s)
664+
try:
665+
parent.wait(timeout=grace_period_s)
666+
except psutil.TimeoutExpired:
667+
log.warning(
668+
f"Encountered timeout attempting to stop endpoint {ep_name},"
669+
" Please try deleting the endpoint again with the --force flag"
670+
)
671+
sys.exit(-1)
665672

666673
# After grace period, give children 1 second, before pulling the plug
667674
terminated, alive = psutil.wait_procs(processes, timeout=grace_period_s)

compute_endpoint/tests/integration/endpoint/endpoint/test_endpoint.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shutil
55
from unittest import mock
66

7+
import psutil
78
import pytest
89
import requests
910
import responses
@@ -157,6 +158,25 @@ def test_endpoint_teardown_execution(mocker, tmp_path, randomstring):
157158
assert tmp_file_content in info_txt
158159

159160

161+
def test_endpoint_psutil_timeout(conf_dir, mocker, ep_uuid):
162+
mocker.patch.object(endpoint.Endpoint, "stop_endpoint")
163+
mocker.patch.object(shutil, "rmtree")
164+
165+
endpoint.Endpoint.configure_endpoint(conf_dir, None)
166+
167+
mock_gcc = mocker.Mock()
168+
mocker.patch(f"{_MOCK_BASE}Endpoint.get_funcx_client").return_value = mock_gcc
169+
170+
mock_gcc.get_endpoint_status.return_value = {"status": "online"}
171+
172+
mock_psutil = mocker.patch(f"{_MOCK_BASE}psutil.Process")
173+
mock_psutil.return_value.wait.side_effect = psutil.TimeoutExpired(10)
174+
175+
endpoint.Endpoint.delete_endpoint(
176+
conf_dir, ep_config=None, force=True, ep_uuid=ep_uuid
177+
)
178+
179+
160180
@pytest.mark.parametrize("web_svc_ok", (True, False))
161181
@pytest.mark.parametrize("force", (True, False))
162182
def test_delete_endpoint(conf_dir, mocker, web_svc_ok, force, ep_uuid):

0 commit comments

Comments
 (0)