Skip to content

Commit 63a24cb

Browse files
fix(di): get pending probes as a copy [backport 3.14] (#14626)
Backport 67da5b5 from #14608 to 3.14. 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 - [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 4d23c32 commit 63a24cb

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
@@ -203,7 +203,7 @@ def unregister(self, *probes: Probe) -> List[Probe]:
203203

204204
def get_pending(self, location: str) -> List[Probe]:
205205
"""Get the currently pending probes by location."""
206-
return self._pending[location]
206+
return self._pending[location].copy()
207207

208208
def __contains__(self, probe: object) -> bool:
209209
"""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
@@ -553,13 +553,16 @@ def test_debugger_multiple_function_probes_on_same_lazy_module():
553553
for i in range(3)
554554
]
555555

556+
sys.modules.pop("tests.submod.stuff", None)
557+
556558
with debugger() as d:
557559
d.add_probes(*probes)
558560

559561
import tests.submod.stuff # noqa:F401
560562

561563
assert len(d._probe_registry) == len(probes)
562564
assert all(_.error_type is None for _ in d._probe_registry.values())
565+
assert len(d._probe_registry._pending) == 0
563566

564567

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

0 commit comments

Comments
 (0)