Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[v3-1-test] Fix memory leak in Client via SSL context creation (#57334)#57374

Merged
potiuk merged 1 commit intov3-1-testfrom
backport-7369e46-v3-1-test
Oct 27, 2025
Merged

[v3-1-test] Fix memory leak in Client via SSL context creation (#57334)#57374
potiuk merged 1 commit intov3-1-testfrom
backport-7369e46-v3-1-test

Conversation

Copy link

github-actions bot commented Oct 27, 2025

related: #56641

When I performed the same memray inspection on the latest version that includes both fixes, the first issue was clearly resolved, but the second issue still persists.
memray1.html

When a Client object is created, ctx = ssl.create_default_context(cafile=ca_file) continues to be executed repeatedly, which accumulates in memory and causes a memory leak. (It appears to be allocated as a C language object and remains in memory regardless of Python object GC)

This PR uses caching to prevent the SSL context object from being recreated.

Here are the results after running for two hours with this change. The memory usage, which was previously growing to tens of MBs, now stabilizes at approximately 700KB.
memray2.html
(cherry picked from commit 7369e46)

Co-authored-by: Jeongwoo Do 48639483+wjddn279@users.noreply.github.com

related: #56641

When I performed the same memray inspection on the latest version that includes both fixes, the first issue was clearly resolved, but the second issue still persists.
[memray1.html](https://github.com/user-attachments/files/23160226/memray1.html)

When a Client object is created, `ctx = ssl.create_default_context(cafile=ca_file)` continues to be executed repeatedly, which accumulates in memory and causes a memory leak. (It appears to be allocated as a C language object and remains in memory regardless of Python object GC)

This PR uses caching to prevent the SSL context object from being recreated.

Here are the results after running for two hours with this change. The memory usage, which was previously growing to tens of MBs, now stabilizes at approximately 700KB.
[memray2.html](https://github.com/user-attachments/files/23160405/memray2.html)
(cherry picked from commit 7369e46)

Co-authored-by: Jeongwoo Do <48639483+wjddn279@users.noreply.github.com>
github-actions bot mentioned this pull request Oct 27, 2025
boring-cyborg bot added the area:task-sdk label Oct 27, 2025
kaxil marked this pull request as ready for review October 27, 2025 22:56
kaxil requested review from amoghrajesh, ashb and kaxil as code owners October 27, 2025 22:56
potiuk approved these changes Oct 27, 2025
potiuk merged commit 88ad427 into v3-1-test Oct 27, 2025
21 checks passed
potiuk deleted the backport-7369e46-v3-1-test branch October 27, 2025 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

potiuk potiuk approved these changes

ashb Awaiting requested review from ashb ashb is a code owner

kaxil Awaiting requested review from kaxil kaxil is a code owner

amoghrajesh Awaiting requested review from amoghrajesh amoghrajesh is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants