Skip to content

Commit eb11df1

Browse files
authored
fix(profiling): fix potential StackCollector deadlock (backport #4108) (#4115)
This is an automatic backport of pull request #4108 done by [Mergify](https://mergify.com). --- <details> <summary>Mergify commands and options</summary> <br /> More conditions and actions can be found in the [documentation](https://docs.mergify.com/). You can also trigger Mergify actions by commenting on this pull request: - `@Mergifyio refresh` will re-evaluate the rules - `@Mergifyio rebase` will rebase this PR on its base branch - `@Mergifyio update` will merge the base branch into this PR - `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch Additionally, on Mergify [dashboard](https://dashboard.mergify.com/) you can: - look at your merge queues - generate the Mergify configuration with the config editor. Finally, you can contact us on https://mergify.com </details>
1 parent d0a3adc commit eb11df1

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

ddtrace/internal/nogevent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def is_module_patched(module):
3737
thread_get_ident = get_original(six.moves._thread.__name__, "get_ident")
3838
Thread = get_original("threading", "Thread")
3939
Lock = get_original("threading", "Lock")
40+
RLock = get_original("threading", "RLock")
4041

4142
is_threading_patched = is_module_patched("threading")
4243

ddtrace/profiling/_threading.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ class _ThreadLink(_thread_link_base):
6969
# Key is a thread_id
7070
# Value is a weakref to an object
7171
_thread_id_to_object = attr.ib(factory=dict, repr=False, init=False, type=typing.Dict[int, _weakref_type])
72-
_lock = attr.ib(factory=nogevent.Lock, repr=False, init=False, type=nogevent.Lock)
72+
# Note that this lock has to be reentrant as spans can be activated unexpectedly in the same thread
73+
# ex. during a gc weakref finalize callback
74+
_lock = attr.ib(factory=nogevent.RLock, repr=False, init=False, type=nogevent.RLock)
7375

7476
def link_object(
7577
self,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
profiling: fix a possible deadlock due to spans being activated unexpectedly.

0 commit comments

Comments
 (0)