Skip to content

Commit eb679cc

Browse files
committed
Servers cannot restart again
1 parent 4239aed commit eb679cc

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

distributed/core.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -310,30 +310,34 @@ async def start_unsafe(self):
310310
return self
311311

312312
async def start(self):
313-
async with self._startup_lock:
314-
if self.status == Status.failed:
315-
assert self.__startup_exc is not None
316-
raise self.__startup_exc
317-
elif self.status != Status.init:
318-
return self
319-
timeout = getattr(self, "death_timeout", None)
320-
321-
async def _close_on_failure(exc: Exception) -> None:
322-
await self.close()
323-
self.status = Status.failed
324-
self.__startup_exc = exc
313+
try:
314+
async with self._startup_lock:
315+
if self.status == Status.failed:
316+
assert self.__startup_exc is not None
317+
raise self.__startup_exc
318+
elif self.status != Status.init:
319+
return self
320+
timeout = getattr(self, "death_timeout", None)
321+
322+
async def _close_on_failure(exc: Exception) -> None:
323+
await self.close()
324+
self.status = Status.failed
325+
self.__startup_exc = exc
325326

326-
try:
327-
await asyncio.wait_for(self.start_unsafe(), timeout=timeout)
328-
except asyncio.TimeoutError as exc:
329-
await _close_on_failure(exc)
330-
raise asyncio.TimeoutError(
331-
f"{type(self).__name__} start timed out after {timeout}s."
332-
) from exc
333-
except Exception as exc:
334-
await _close_on_failure(exc)
335-
raise RuntimeError(f"{type(self).__name__} failed to start.") from exc
336-
self.status = Status.running
327+
try:
328+
await asyncio.wait_for(self.start_unsafe(), timeout=timeout)
329+
except asyncio.TimeoutError as exc:
330+
await _close_on_failure(exc)
331+
raise asyncio.TimeoutError(
332+
f"{type(self).__name__} start timed out after {timeout}s."
333+
) from exc
334+
except Exception as exc:
335+
await _close_on_failure(exc)
336+
raise RuntimeError(
337+
f"{type(self).__name__} failed to start."
338+
) from exc
339+
self.status = Status.running
340+
finally:
337341
self.__started.set()
338342
return self
339343

@@ -515,7 +519,7 @@ async def handle_comm(self, comm):
515519
logger.debug("Connection from %r to %s", address, type(self).__name__)
516520
self._comms[comm] = op
517521

518-
await self
522+
await self.__started.wait()
519523
try:
520524
while not self.__stopped:
521525
try:

0 commit comments

Comments
 (0)