server: handle event exceptions

Don't allow exceptions to propagate beyond a call to
_process_event().  Make sure the future is not marked
as done prior to setting the result.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-06-27 10:49:43 -04:00
parent 4bed314b0a
commit 1eaead1073
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 11 additions and 7 deletions

View File

@ -293,13 +293,17 @@ class Server:
) -> None:
events = self.events.get(event, [])
coroutines: List[Coroutine] = []
for func in events:
ret = func(*args)
if ret is not None:
coroutines.append(ret)
if coroutines:
await asyncio.gather(*coroutines)
fut.set_result(None)
try:
for func in events:
ret = func(*args)
if ret is not None:
coroutines.append(ret)
if coroutines:
await asyncio.gather(*coroutines)
except ServerError as e:
logging.exception(f"Error Processing Event: {fut}")
if not fut.done():
fut.set_result(None)
def register_remote_method(self,
method_name: str,