You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
getting ssl.SSLSocket.session brings to memory leak #116810
importsslimportsocketimporttimehost='192.168.16.66'# some server we can connect with https as exampleport=443session=Nonecontext=ssl._create_unverified_context(protocol=ssl.PROTOCOL_TLSv1_2)
withsocket.create_connection((host, port)) assock:
withcontext.wrap_socket(sock, server_hostname=host, session=session) asssock:
foriinrange(300000):
session=ssock.sessionprint('Sleeping')
time.sleep(200)
Here is part of script that is used for "ssl reuse" session during connection to server
Running this script brings to memory leak (process memory increased from 322Mb to 2.5Gb).
Memory is not freed on "time.sleep" instruction
Not reproduced on python 3.8
I'm using cherrypy to run a very simple HTTPS web service. It started leaking memory when switched from python3.9 to python3.11. Very likely the same issue.
Specifically, the function PySSL_get_session( ) has a work around for a bug in OpenSSL 1.1.0. However, the move from Python 3.9 to 3.11 removed the macros for OpenSSL versions. Now, the session is duplicated (by _ssl_session_dup( )) and pointer is saved in the session variable. Next SSL_get1_session( ) is used to return a pointer to the session and overwrites the address saved in the session variable. The duplicated session is leaked.
Activity
stanleyu commentedon Aug 22, 2024
I'm using cherrypy to run a very simple HTTPS web service. It started leaking memory when switched from python3.9 to python3.11. Very likely the same issue.
jeffvanvoorst commentedon Aug 22, 2024
Specifically, the function PySSL_get_session( ) has a work around for a bug in OpenSSL 1.1.0. However, the move from Python 3.9 to 3.11 removed the macros for OpenSSL versions. Now, the session is duplicated (by _ssl_session_dup( )) and pointer is saved in the session variable. Next SSL_get1_session( ) is used to return a pointer to the session and overwrites the address saved in the session variable. The duplicated session is leaked.
pythongh-116810: fixed memory leak ssl module
gh-116810: fix memory leak in ssl module (GH-123249)
pythongh-116810: fix memory leak in ssl module (pythonGH-123249)
pythongh-116810: fix memory leak in ssl module (pythonGH-123249)
[3.12] gh-116810: fix memory leak in ssl module (GH-123249) (GH-124801)
[3.13] gh-116810: fix memory leak in ssl module (GH-123249) (#124800)