From e3ab594d57c6ec01b8124ed35c70f77291963f49 Mon Sep 17 00:00:00 2001 From: fjetter Date: Tue, 24 May 2022 11:15:46 +0200 Subject: [PATCH] Do not attempt to connect to Nanny if in status==init --- distributed/worker.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/distributed/worker.py b/distributed/worker.py index 96742d7f92..1795bb80c5 100644 --- a/distributed/worker.py +++ b/distributed/worker.py @@ -1450,13 +1450,19 @@ async def close( # is the other way round. If an external caller wants to close # nanny+worker, the nanny must be notified first. ==> Remove kwarg # nanny, see also Scheduler.retire_workers - if self.status in (Status.closed, Status.closing): + if self.status in (Status.closed, Status.closing, Status.failed): await self.finished() return - if self.status not in WORKER_ANY_RUNNING: - # We may not be able to reliably communicate with the Nanny, so don't try. - # Otherwise, the Nanny RPC call may hang, especially during worker/nanny startup. + if self.status == Status.init: + # If the worker is still in startup/init and is started by a nanny, + # this means the nanny itself is not up, yet. If the Nanny isn't up, + # yet, it's server will not accept any incoming RPC requests and + # will block until the startup is finished. + # Therefore, this worker trying to communicate with the Nanny during + # startup is not possible and we cannot close it. + # In this case, the Nanny will automatically close after inspecting + # the worker status nanny = False disable_gc_diagnosis()