Skip to content

Commit

Permalink
fix(aioredis): handle all BaseException, not Exception in _finish_span (
Browse files Browse the repository at this point in the history
#4193) (#4198)

## Description
This fixes the aioredis integration from raising `CancelledError`. As of Python 3.8 ([Docs link](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.CancelledError)), `CancelledError` now extends from `BaseException` and not `Exception`, and is currently being raised by the aioredis integration instead of being handled. The aioredis integration now catches all errors extending from `BaseException` in aioredis futures (i.e. the `_finish_span()` callback added to each future).

This should resolve #3253.

(cherry picked from commit 313a938)

Co-authored-by: Yun Kim <35776586+Yun-Kim@users.noreply.github.com>
Co-authored-by: Kyle Verhoog <kyle@verhoog.ca>
  • Loading branch information
3 people authored Sep 21, 2022
1 parent d7864be commit f6b04d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ddtrace/contrib/aioredis/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ def traced_13_execute_command(func, instance, args, kwargs):
def _finish_span(future):
try:
# Accessing the result will raise an exception if:
# - The future was cancelled
# - The future was cancelled (CancelledError)
# - There was an error executing the future (`future.exception()`)
# - The future is in an invalid state
future.result()
except Exception:
# CancelledError exceptions extend from BaseException as of Python 3.8, instead of usual Exception
except BaseException:
span.set_exc_info(*sys.exc_info())
finally:
span.finish()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
aioredis: added exception handling for `CancelledError` in the aioredis integration.

0 comments on commit f6b04d5

Please sign in to comment.