Skip to content

Commit 1c3520a

Browse files
authored
Merge pull request syslog-ng#5149 from HofiOne/s3-memleak-fix
s3: workaround on-reload memleak when no role is set
2 parents 2bec121 + 3d8aa70 commit 1c3520a

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

modules/python-modules/syslogng/modules/s3/s3_destination.py

+21-10
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,16 @@ def open(self) -> bool:
249249
if self.is_opened():
250250
return True
251251

252-
self.session = Session(
253-
aws_access_key_id=self.access_key if self.access_key != "" else None,
254-
aws_secret_access_key=self.secret_key if self.secret_key != "" else None,
255-
region_name=self.region,
256-
)
257-
252+
# NOTE: Creating a client via a Session object does some unusual caching, which increases memory usage
253+
# NOTE: each reload. Because of this, we only create Session object if the role is set, and in that case
254+
# NOTE: the memory usage is expected to behave unusually. Sometime we should investigate this further.
258255
if self.role != "":
256+
self.session = Session(
257+
aws_access_key_id=self.access_key if self.access_key != "" else None,
258+
aws_secret_access_key=self.secret_key if self.secret_key != "" else None,
259+
region_name=self.region,
260+
)
261+
259262
# NOTE: The Session.set_credentials always creates a new Credentials object from the given keys.
260263
# NOTE: The DeferredRefreshableCredentials class is a child of RefreshableCredentials which is a
261264
# NOTE: child of the Credentials class.
@@ -271,10 +274,18 @@ def open(self) -> bool:
271274
whoami = sts.get_caller_identity().get("Arn")
272275
self.logger.info(f"Using {whoami} to access the bucket")
273276

274-
self.client = self.session.client(
275-
service_name="s3",
276-
endpoint_url=self.url if self.url != "" else None,
277-
)
277+
self.client = self.session.client(
278+
service_name="s3",
279+
endpoint_url=self.url if self.url != "" else None,
280+
)
281+
else:
282+
self.client = client(
283+
service_name="s3",
284+
endpoint_url=self.url if self.url != "" else None,
285+
aws_access_key_id=self.access_key if self.access_key != "" else None,
286+
aws_secret_access_key=self.secret_key if self.secret_key != "" else None,
287+
region_name=self.region,
288+
)
278289

279290
is_opened = False
280291
try:

news/bugfix-5149.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
`s3()`: Eliminated indefinite memory usage increase for each reload.
2+
3+
The increased memory usage is caused by the `botocore` library, which
4+
caches the session information. We only need the Session object, if
5+
`role()` is set. The increased memory usage still happens with that set,
6+
currently we only fixed the unset case.

0 commit comments

Comments
 (0)