Skip to content

Commit 963e6e0

Browse files
committed
fix(di): get pending probe as a copy
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.
1 parent 6f8f8a0 commit 963e6e0

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)