Skip to content

Commit 2e75621

Browse files
github-actions[bot]emmettbutlermabdinur
authored
fix: avoid crashing when asm env doesnt exist during finalise() [backport 1.18] (#6848)
Backport d534fd5 from #6669 to 1.18. This fix addresses the crash described in #6659 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] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [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)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly 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: Emmett Butler <[email protected]> Co-authored-by: Munir Abdinur <[email protected]>
1 parent b7e5354 commit 2e75621

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

ddtrace/appsec/_asm_request_context.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,13 @@ def __init__(self):
130130
def finalise(self):
131131
if self.active:
132132
env = self.execution_context.get_item("asm_env")
133-
# assert _CONTEXT_ID.get() == self._id
134-
callbacks = GLOBAL_CALLBACKS.get(_CONTEXT_CALL, []) + env.callbacks.get(_CONTEXT_CALL)
135-
if callbacks is not None:
136-
for function in callbacks:
137-
function(env)
133+
callbacks = GLOBAL_CALLBACKS.get(_CONTEXT_CALL, [])
134+
if env is not None and env.callbacks is not None and env.callbacks.get(_CONTEXT_CALL):
135+
callbacks += env.callbacks.get(_CONTEXT_CALL)
136+
if callbacks:
137+
if env is not None:
138+
for function in callbacks:
139+
function(env)
138140
self.execution_context.end()
139141
self.active = False
140142

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)