Skip to content

Commit

Permalink
Retry on EADDRINUSE.
Browse files Browse the repository at this point in the history
  • Loading branch information
moodyjon authored and jackrobison committed Sep 28, 2022
1 parent bc4e3aa commit 0f33f2b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions hub/herald/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import math
import time
import errno
import codecs
import typing
import asyncio
Expand Down Expand Up @@ -273,6 +274,7 @@ async def _start_server(self, kind, *args, **kw_args):
except OSError as e: # don't suppress CancelledError
self.logger.error(f'{kind} server failed to listen on {host}:'
f'{port:d} :{e!r}')
raise
else:
self.logger.info(f'{kind} server listening on {host}:{port:d}')

Expand All @@ -282,8 +284,19 @@ async def _start_external_servers(self):
"""
env = self.env
host = env.cs_host()
if env.tcp_port is not None:
await self._start_server('TCP', host, env.tcp_port)
if env.tcp_port is None:
return
started = False
while not started:
try:
await self._start_server('TCP', host, env.tcp_port)
started = True
except OSError as e:
if e.errno is errno.EADDRINUSE:
await asyncio.sleep(3)
continue
raise


async def _close_servers(self, kinds):
"""Close the servers of the given kinds (TCP etc.)."""
Expand Down

0 comments on commit 0f33f2b

Please sign in to comment.