Skip to content

Commit

Permalink
Merge pull request #58 from demisto/hod/fix_memory_leak
Browse files Browse the repository at this point in the history
Adding env variable that will allow us to not cache the last response
  • Loading branch information
hod-alpert authored Dec 30, 2020
2 parents 4491333 + 530e3bd commit aa97c7a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[PyPI History][1]

[1]: https://pypi.org/project/demisto-py/#history
## 2.0.22
* don't cache last response in case `DONT_CACHE_LAST_RESPONSE` environment variable is set to true, this to avoid memory leaks.

## 2.0.20
* Log only headers in exceptions when `DEMISTO_EXCEPTION_HEADER_LOGGING` environment variable is set to true. This protects against possible sensitive data being logged in exceptions.
Expand Down
4 changes: 3 additions & 1 deletion demisto_client/demisto_api/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ApiClient(object):
to the API
"""

CACHE_LAST_RESPONSE = not os.environ.get("DONT_CACHE_LAST_RESPONSE", False)
PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types
NATIVE_TYPES_MAPPING = {
'int': int,
Expand Down Expand Up @@ -160,7 +161,8 @@ def __call_api(
_preload_content=_preload_content,
_request_timeout=_request_timeout)

self.last_response = response_data
if self.CACHE_LAST_RESPONSE:
self.last_response = response_data

return_data = response_data
if _preload_content:
Expand Down
3 changes: 3 additions & 0 deletions gen-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ sed -i "${INPLACE[@]}" -e "${start}a\\
\ \ \ \ \ \ \ \ classifier_data_json = json.loads(data)\\
\ \ \ \ \ \ \ \ classifier_id = classifier_data_json.get('id')" demisto_client/demisto_api/api/default_api.py

sed -i "${INPLACE[@]}" -e 's/PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types/CACHE_LAST_RESPONSE = not os.environ.get("DONT_CACHE_LAST_RESPONSE", False)\
PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types/' -e 's/self.last_response = response_data/if self.CACHE_LAST_RESPONSE:\
self.last_response = response_data/' demisto_client/demisto_api/api_client.py
# End fix import_classifier

# remove files not used
Expand Down

0 comments on commit aa97c7a

Please sign in to comment.