fix(pubsub): fix unhandled exception in subscriber task #815
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
We have seen unhandled exceptions making their way to the root unhandled exception handler of the event loop in our application that uses pubsub subscribe(), as in the below Traceback. Whilst our application catches the relevant aiohttp errors when awaiting the subscribe() call, this exception remained unhandled. This is because subscribe was ignoring the tasks returned from the calls to asyncio.wait(), meaning any exception results on these tasks would not be handled and the tasks would get deleted when subscribe() returned.
Fix this by gathering the results of all worker tasks before returning from subscribe(). Given that we're about to raise
asyncio.CancelledError() and return, there's no point in raising the internal errors here, so just log them.