Skip to content

Commit 99a20b0

Browse files
P403n1x87github-actions[bot]
authored andcommitted
fix(di): get pending probes as a copy (#14608)
When retrieving the list of pending probes, we make the registry return a copy of the collection to avoid mutation during iteration. In the worst case, Python does not warn that the list has been mutated while iterating over it, causing the iteration loop to end prematurely without any sings of errors. ## 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 - [ ] 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) (cherry picked from commit 67da5b5)
1 parent a85f22c commit 99a20b0

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

ddtrace/debugging/_probe/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def unregister(self, *probes: Probe) -> List[Probe]:
195195

196196
def get_pending(self, location: str) -> List[Probe]:
197197
"""Get the currently pending probes by location."""
198-
return self._pending[location]
198+
return self._pending[location].copy()
199199

200200
def __contains__(self, probe: object) -> bool:
201201
"""Check if a probe is in the registry."""
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: fix an issue that prevented multiple probes on the
5+
same location from being instrumented.

tests/debugging/test_debugger.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,13 +539,16 @@ def test_debugger_multiple_function_probes_on_same_lazy_module():
539539
for i in range(3)
540540
]
541541

542+
sys.modules.pop("tests.submod.stuff", None)
543+
542544
with debugger() as d:
543545
d.add_probes(*probes)
544546

545547
import tests.submod.stuff # noqa:F401
546548

547549
assert len(d._probe_registry) == len(probes)
548550
assert all(_.error_type is None for _ in d._probe_registry.values())
551+
assert len(d._probe_registry._pending) == 0
549552

550553

551554
# DEV: The following tests are to ensure compatibility with the tracer

0 commit comments

Comments
 (0)