Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion ddtrace/bootstrap/sitecustomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,18 @@ def drop(module_name):
# uses a copy of that module that is distinct from the copy that user code
# gets when it does `import threading`. The same applies to every module
# not in `KEEP_MODULES`.
KEEP_MODULES = frozenset(["atexit", "ddtrace", "asyncio", "concurrent", "typing", "logging", "attr"])
KEEP_MODULES = frozenset(
[
"atexit",
"ddtrace",
"asyncio",
"concurrent",
"typing",
"logging",
"attr",
"google.protobuf", # the upb backend in >= 4.21 does not like being unloaded
]
)
if PY2:
KEEP_MODULES_PY2 = frozenset(["encodings", "codecs"])
for m in list(_ for _ in sys.modules if _ not in LOADED_MODULES):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
profiler: Fixed a bug that caused segmentation faults in applications that
use protobuf as a runtime dependency.
17 changes: 17 additions & 0 deletions tests/profiling/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,20 @@ def test_memalloc_no_init_error_on_fork():
if not pid:
exit(0)
os.waitpid(pid, 0)


@pytest.mark.subprocess(
ddtrace_run=True,
env=dict(
DD_PROFILING_ENABLED="1",
DD_UNLOAD_MODULES_FROM_SITECUSTOMIZE="1",
),
out="OK\n",
err=None,
)
def test_profiler_start_up_with_module_clean_up_in_protobuf_app():
# This can cause segfaults if we do module clean up with later versions of
# protobuf. This is a regression test.
from google.protobuf import empty_pb2 # noqa

print("OK")