-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: pytest deadlock when using gevent [backport 2.8] #9166
Conversation
Fixes #8281 This fix resolves an issue when using ``pytest`` + ``gevent`` where the telemetry writer was eager initialized by ``pytest`` entrypoints loading of our plugin causing a potential dead lock. The specific case that we targeted solving with this PR: ```python import ddtrace import gevent.monkey gevent.monkey.patch_all() def test_thing(): pass ``` ```shell $ pytest test.py $ pytest -p ddtrace -p ddtrace.pytest_bdd -p ddtrace.pytest_benchmark test.py $ pytest -p no:ddtrace -p no:ddtrace.pytest_bdd -p no:ddtrace.pytest_benchmark test.py ``` Previously would dead-lock, but now will execute without problem. We no longer get telemetry enabled and sending data just from `import ddtrace`. Moving telemetry writer starting to `ddtrace.bootstrap.preload` will mean that any unhandled exceptions that occur before the telemetry writer can be started will not get reported. - [x] Change(s) are motivated and described in the PR description - [x] Testing strategy is described if automated tests are not included in the PR - [x] Risks are described (performance impact, potential for breakage, maintainability) - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed or label `changelog/no-changelog` is set - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)) - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) - [x] If this PR changes the public interface, I've notified `@DataDog/apm-tees`. - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) (cherry picked from commit 9e862f9)
Datadog ReportBranch report: ✅ 0 Failed, 171574 Passed, 1095 Skipped, 11h 42m 15.71s Total duration (25m 59.15s time saved) New Flaky Tests (1)
|
BenchmarksBenchmark execution time: 2024-05-06 18:32:09 Comparing candidate commit f83a6a1 in PR branch Found 13 performance improvements and 23 performance regressions! Performance is the same for 165 metrics, 9 unstable metrics. scenario:coreapiscenario-context_with_data_no_listeners
scenario:coreapiscenario-context_with_data_only_all_listeners
scenario:coreapiscenario-core_dispatch_listeners
scenario:coreapiscenario-core_dispatch_no_listeners
scenario:coreapiscenario-core_dispatch_only_all_listeners
scenario:coreapiscenario-core_dispatch_with_results_listeners
scenario:coreapiscenario-core_dispatch_with_results_no_listeners
scenario:coreapiscenario-get_item_exists
scenario:coreapiscenario-get_item_missing
scenario:coreapiscenario-set_item
scenario:flasksimple-appsec-telemetry
scenario:httppropagationextract-b3_headers
scenario:httppropagationextract-full_t_id_datadog_headers
scenario:httppropagationextract-invalid_trace_id_header
scenario:httppropagationextract-large_header_no_matches
scenario:httppropagationextract-medium_header_no_matches
scenario:httppropagationextract-none_propagation_style
scenario:httppropagationextract-tracecontext_headers
scenario:httppropagationextract-wsgi_invalid_span_id_header
scenario:httppropagationextract-wsgi_invalid_trace_id_header
scenario:httppropagationextract-wsgi_large_header_no_matches
scenario:httppropagationextract-wsgi_medium_header_no_matches
scenario:httppropagationinject-ids_only
scenario:httppropagationinject-with_tags_invalid
scenario:otelspan-start-finish
scenario:sethttpmeta-all-disabled
scenario:sethttpmeta-all-enabled
scenario:sethttpmeta-obfuscation-regular-case-implicit-query
scenario:sethttpmeta-obfuscation-send-querystring-disabled
scenario:sethttpmeta-obfuscation-worst-case-explicit-query
scenario:sethttpmeta-obfuscation-worst-case-implicit-query
scenario:sethttpmeta-useragentvariant_not_exists_1
scenario:span-add-tags
scenario:span-start-finish
scenario:span-start-finish-telemetry
scenario:span-start-finish-traceid128
|
Backport 9e862f9 from #9141 to 2.8.
Fixes #8281
This fix resolves an issue when using
pytest
+gevent
where the telemetry writer was eager initialized bypytest
entrypoints loading of our plugin causing a potential dead lock.The specific case that we targeted solving with this PR:
Previously would dead-lock, but now will execute without problem.
We no longer get telemetry enabled and sending data just from
import ddtrace
.Moving telemetry writer starting to
ddtrace.bootstrap.preload
will mean that any unhandled exceptions that occur before the telemetry writer can be started will not get reported.Change(s) are motivated and described in the PR description
Testing strategy is described if automated tests are not included in the PR
Risks are described (performance impact, potential for breakage, maintainability)
Change is maintainable (easy to change, telemetry, documentation)
Library release note guidelines are followed or label
changelog/no-changelog
is setDocumentation is included (in-code, generated user docs, public corp docs)
Backport labels are set (if applicable)
If this PR changes the public interface, I've notified
@DataDog/apm-tees
.Title is accurate
All changes are related to the pull request's stated goal
Description motivates each change
Avoids breaking API changes
Testing strategy adequately addresses listed risks
Change is maintainable (easy to change, telemetry, documentation)
Release note makes sense to a user of the library
Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
Backport labels are set in a manner that is consistent with the release branch maintenance
policy