Skip to content

Commit dd33f09

Browse files
fix(aioredis): handle all BaseException, not Exception in _finish_span (#4193) (#4195)
## 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 <[email protected]>
1 parent 1d244a5 commit dd33f09

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ddtrace/contrib/aioredis/patch.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,12 @@ def traced_13_execute_command(func, instance, args, kwargs):
140140
def _finish_span(future):
141141
try:
142142
# Accessing the result will raise an exception if:
143-
# - The future was cancelled
143+
# - The future was cancelled (CancelledError)
144144
# - There was an error executing the future (`future.exception()`)
145145
# - The future is in an invalid state
146146
future.result()
147-
except Exception:
147+
# CancelledError exceptions extend from BaseException as of Python 3.8, instead of usual Exception
148+
except BaseException:
148149
span.set_exc_info(*sys.exc_info())
149150
finally:
150151
span.finish()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
aioredis: added exception handling for `CancelledError` in the aioredis integration.

0 commit comments

Comments
 (0)