Skip to content

Commit 097267c

Browse files
fix: asm None env [backport 2.7] (#8654)
Backport 7c0f0dc from #8646 to 2.7. This fix addresses the crash described in #8644 and #6659 and by defensively handling None values for the asm_env object during _DataHandler shutdown. The root cause of this issue is unknown. There are no tests added here because we don't have a replication case. ## Checklist - [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] If change touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. ## Reviewer Checklist - [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) Co-authored-by: Stefano Polloni <[email protected]>
1 parent 20f2321 commit 097267c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

ddtrace/appsec/_asm_request_context.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,17 @@ def __init__(self):
150150

151151
def finalise(self):
152152
if self.active:
153+
self.active = False
153154
env = self.execution_context.get_item("asm_env")
154-
callbacks = GLOBAL_CALLBACKS.get(_CONTEXT_CALL, []) if env.must_call_globals else []
155-
env.must_call_globals = False
156-
if env is not None and env.callbacks is not None and env.callbacks.get(_CONTEXT_CALL):
157-
callbacks = callbacks + env.callbacks.get(_CONTEXT_CALL)
158-
if callbacks:
159-
if env is not None:
155+
if env is not None:
156+
callbacks = GLOBAL_CALLBACKS.get(_CONTEXT_CALL, []) if env.must_call_globals else []
157+
env.must_call_globals = False
158+
if env.callbacks is not None and env.callbacks.get(_CONTEXT_CALL):
159+
callbacks = callbacks + env.callbacks.get(_CONTEXT_CALL)
160+
if callbacks:
160161
for function in callbacks:
161162
function(env)
162163
self.execution_context.end()
163-
self.active = False
164164

165165

166166
def set_value(category: str, address: str, value: Any) -> None:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
appsec: This fix resolves an issue in which the library attempted to finalize twice a context object used
5+
by the Application Security Management product.

0 commit comments

Comments
 (0)