Skip to content

Commit 8ecaa16

Browse files
fix(di): prevent exception when removing unresolved probe [backport 2.21] (#13385)
Backport ebc7e4d from #13357 to 2.21. We prevent an exception from occurring when trying to remove a probe that did not resolve to a valid source code location. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Gabriele N. Tornetta <[email protected]>
1 parent c2fb9db commit 8ecaa16

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

ddtrace/debugging/_probe/registry.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ def log_probes_status(self) -> None:
151151

152152
def _remove_pending(self, probe: Probe) -> None:
153153
location = _get_probe_location(probe)
154-
155-
# Pending probes must have valid location information
156-
assert location is not None, probe # nosec
154+
if location is None:
155+
# If the probe has no location information, then it cannot be
156+
# pending.
157+
return
157158

158159
pending_probes = self._pending[location]
159160
try:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
dynamic instrumentation: prevent an exception when trying to remove a probe
5+
that did not resolve to a valid source code location.

tests/debugging/probe/test_registry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def test_registry_location_error():
5656
# Check that the probe is not pending
5757
assert not registry.get_pending(__file__)
5858

59+
# Check that unregistering the probe does not cause an exception
60+
registry.unregister(probe)
61+
5962
# Check that we emitted the correct diagnostic error message
6063
for e in status_logger.queue:
6164
del e["timestamp"]

0 commit comments

Comments
 (0)