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

Log rather than raise exceptions in preload.teardown() #6458

Merged
merged 2 commits into from
May 26, 2022
Merged
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
5 changes: 4 additions & 1 deletion distributed/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3368,7 +3368,10 @@ async def close(self):
setproctitle("dask-scheduler [closing]")

for preload in self.preloads:
await preload.teardown()
try:
await preload.teardown()
except Exception as e:
logger.exception(e)

await asyncio.gather(
*[plugin.close() for plugin in list(self.plugins.values())]
Expand Down
18 changes: 18 additions & 0 deletions distributed/tests/test_preload.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
import re
import shutil
Expand Down Expand Up @@ -281,6 +282,23 @@ def dask_setup(client, value):
assert c.foo == value


@gen_test()
async def test_teardown_failure_doesnt_crash_scheduler():
text = """
def dask_teardown(worker):
raise Exception(123)
"""

with captured_logger(logging.getLogger("distributed.scheduler")) as s_logger:
with captured_logger(logging.getLogger("distributed.worker")) as w_logger:
async with Scheduler(dashboard_address=":0", preload=text) as s:
async with Worker(s.address, preload=[text]) as w:
pass

assert "123" in s_logger.getvalue()
assert "123" in w_logger.getvalue()


@gen_cluster(nthreads=[])
async def test_client_preload_config_click(s):
text = dedent(
Expand Down
5 changes: 4 additions & 1 deletion distributed/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,10 @@ async def close(
)

for preload in self.preloads:
await preload.teardown()
try:
await preload.teardown()
except Exception as e:
logger.exception(e)

for extension in self.extensions.values():
if hasattr(extension, "close"):
Expand Down