Skip to content

Commit

Permalink
Address feedback. Broaden logging to more types of Exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
moodyjon authored and jackrobison committed Sep 28, 2022
1 parent 0f33f2b commit 9b17822
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
22 changes: 19 additions & 3 deletions hub/elastic_sync/service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import errno
import os
import json
import typing
Expand Down Expand Up @@ -55,9 +56,24 @@ def open_db(self):
)

async def run_es_notifier(self, synchronized: asyncio.Event):
server = await asyncio.get_event_loop().create_server(
lambda: ElasticNotifierProtocol(self._listeners), self.env.elastic_notifier_host, self.env.elastic_notifier_port
)
started = False
while not started:
try:
server = await asyncio.get_event_loop().create_server(
lambda: ElasticNotifierProtocol(self._listeners),
self.env.elastic_notifier_host,
self.env.elastic_notifier_port
)
started = True
except Exception as e:
if not isinstance(e, asyncio.CancelledError):
self.log.error(f'ES notifier server failed to listen on '
f'{self.env.elastic_notifier_host}:'
f'{self.env.elastic_notifier_port:d} : {e!r}')
if isinstance(e, OSError) and e.errno is errno.EADDRINUSE:
await asyncio.sleep(3)
continue
raise
self.log.info("ES notifier server listening on TCP %s:%i", self.env.elastic_notifier_host,
self.env.elastic_notifier_port)
synchronized.set()
Expand Down
7 changes: 4 additions & 3 deletions hub/herald/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,10 @@ async def _start_server(self, kind, *args, **kw_args):
host, port = args[:2]
try:
self.servers[kind] = await loop.create_server(protocol_factory, *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}')
except Exception as e:
if not isinstance(e, asyncio.CancelledError):
self.logger.error(f'{kind} server failed to listen on '
f'{host}:{port:d} : {e!r}')
raise
else:
self.logger.info(f'{kind} server listening on {host}:{port:d}')
Expand Down

0 comments on commit 9b17822

Please sign in to comment.