From e631ad76ec95c6673ef5c1f766ee91192cadc6fd Mon Sep 17 00:00:00 2001 From: "Gabriele N. Tornetta" Date: Tue, 11 Jul 2023 15:39:50 +0100 Subject: [PATCH] fix: keep the sre_constants module (#6255) The re module imports from the sre_constants module at runtime. This might cause issues when modules are unloaded in the sitecustomize. Fixes #6197. (cherry picked from commit cda30010de464f578ea11d98b91ff59aa76ee821) --- ddtrace/bootstrap/sitecustomize.py | 1 + .../notes/fix-re-unload-8770a3d497234243.yaml | 5 +++++ tests/commands/test_runner.py | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 releasenotes/notes/fix-re-unload-8770a3d497234243.yaml diff --git a/ddtrace/bootstrap/sitecustomize.py b/ddtrace/bootstrap/sitecustomize.py index b35419d6648..6c689a5262e 100644 --- a/ddtrace/bootstrap/sitecustomize.py +++ b/ddtrace/bootstrap/sitecustomize.py @@ -109,6 +109,7 @@ def drop(module_name): "concurrent", "typing", "re", # referenced by the typing module + "sre_constants", # imported by re at runtime "logging", "attr", "google.protobuf", # the upb backend in >= 4.21 does not like being unloaded diff --git a/releasenotes/notes/fix-re-unload-8770a3d497234243.yaml b/releasenotes/notes/fix-re-unload-8770a3d497234243.yaml new file mode 100644 index 00000000000..ae19172ad65 --- /dev/null +++ b/releasenotes/notes/fix-re-unload-8770a3d497234243.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed a bug that caused applications using gevent and cassandra to fail to + start with the ddtrace-run command. diff --git a/tests/commands/test_runner.py b/tests/commands/test_runner.py index 8e34641a3ef..47124f30385 100644 --- a/tests/commands/test_runner.py +++ b/tests/commands/test_runner.py @@ -468,3 +468,16 @@ def test_no_args(): p.wait() assert p.returncode == 1 assert six.b("usage:") in p.stdout.read() + + +@pytest.mark.subprocess(ddtrace_run=True, env=dict(DD_UNLOAD_MODULES_FROM_SITECUSTOMIZE="1")) +def test_ddtrace_re_module(): + import re + + re.Scanner( + ( + ("frozen", None), + (r"[a-zA-Z0-9_]+", lambda s, t: t), + (r"[\s,<>]", None), + ) + )