Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a crash when there is a timeout when shutting down the Dask cluster #2580

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion esmvalcore/config/_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@ def get_distributed_client():
if client is not None:
client.close()
if cluster is not None:
cluster.close()
try:
cluster.close()
except TimeoutError:
logger.warning(
"Failed to shut down the cluster at %s",
cluster.scheduler_address,
)
7 changes: 5 additions & 2 deletions tests/unit/config/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def test_get_distributed_client_external(mocker, tmp_path, warn_unused_args):
mock_client.close.assert_called()


def test_get_distributed_client_slurm(mocker, tmp_path):
@pytest.mark.parametrize("shutdown_timeout", [False, True])
def test_get_distributed_client_slurm(mocker, tmp_path, shutdown_timeout):
cfg = {
"cluster": {
"type": "dask_jobqueue.SLURMCluster",
Expand Down Expand Up @@ -66,10 +67,12 @@ def test_get_distributed_client_slurm(mocker, tmp_path):
create_autospec=True,
return_value=mock_module,
)
mock_cluster = mock_cluster_cls.return_value
if shutdown_timeout:
mock_cluster.close.side_effect = TimeoutError
with _dask.get_distributed_client() as client:
assert client is mock_client
mock_client.close.assert_called()
mock_cluster = mock_cluster_cls.return_value
_dask.Client.assert_called_with(address=mock_cluster.scheduler_address)
args = {k: v for k, v in cfg["cluster"].items() if k != "type"}
mock_cluster_cls.assert_called_with(**args)
Expand Down