Skip to content

Commit

Permalink
Merge branch '1.x' into chore/gevent-on-fork
Browse files Browse the repository at this point in the history
  • Loading branch information
P403n1x87 authored Aug 18, 2022
2 parents fba851c + 81548b9 commit 8721108
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
1 change: 1 addition & 0 deletions ddtrace/internal/nogevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def is_module_patched(module):
thread_get_ident = get_original(six.moves._thread.__name__, "get_ident")
Thread = get_original("threading", "Thread")
Lock = get_original("threading", "Lock")
RLock = get_original("threading", "RLock")

is_threading_patched = is_module_patched("threading")

Expand Down
4 changes: 3 additions & 1 deletion ddtrace/profiling/_threading.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class _ThreadLink(_thread_link_base):
# Key is a thread_id
# Value is a weakref to an object
_thread_id_to_object = attr.ib(factory=dict, repr=False, init=False, type=typing.Dict[int, _weakref_type])
_lock = attr.ib(factory=nogevent.Lock, repr=False, init=False, type=nogevent.Lock)
# Note that this lock has to be reentrant as spans can be activated unexpectedly in the same thread
# ex. during a gc weakref finalize callback
_lock = attr.ib(factory=nogevent.RLock, repr=False, init=False, type=nogevent.RLock)

def link_object(
self,
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class DatadogSampler(RateByServiceSampler):
provided. It is not used when the agent supplied sample rates are used.
"""

__slots__ = ("limiter", "rules", "_default_sampler")
__slots__ = ("limiter", "rules")

NO_RATE_LIMIT = -1
DEFAULT_RATE_LIMIT = 100
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
profiling: fix a possible deadlock due to spans being activated unexpectedly.
26 changes: 7 additions & 19 deletions tests/internal/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def ensure_no_module_watchdog():
if was_installed:
ModuleWatchdog.uninstall()

yield

if was_installed:
ModuleWatchdog.install()
try:
yield
finally:
if was_installed:
ModuleWatchdog.install()


@pytest.fixture
Expand Down Expand Up @@ -80,11 +81,6 @@ def test_import_origin_hook_for_module_not_yet_imported():
path = os.getenv("MODULE_ORIGIN")
hook = mock.Mock()

try:
ModuleWatchdog.install()
except RuntimeError:
pass

ModuleWatchdog.register_origin_hook(path, hook)

hook.assert_not_called()
Expand Down Expand Up @@ -118,11 +114,6 @@ def test_import_module_hook_for_module_not_yet_imported():
name = "tests.test_module"
hook = mock.Mock()

try:
ModuleWatchdog.install()
except RuntimeError:
pass

ModuleWatchdog.register_module_hook(name, hook)

hook.assert_not_called()
Expand Down Expand Up @@ -157,11 +148,6 @@ def test_module_deleted():
path = os.getenv("MODULE_ORIGIN")
hook = mock.Mock()

try:
ModuleWatchdog.install()
except RuntimeError:
pass

ModuleWatchdog.register_origin_hook(path, hook)
ModuleWatchdog.register_module_hook(name, hook)

Expand Down Expand Up @@ -351,3 +337,5 @@ def test_module_watchdog_dict_shallow_copy():

# Ensure that they match
assert original_modules == new_modules

ModuleWatchdog.uninstall()

0 comments on commit 8721108

Please sign in to comment.