Skip to content

gh-148292: Update ssl._SSLSocket for OpenSSL 4 - #149102

Merged
vstinner merged 10 commits into
python:mainfrom
vstinner:ssl_got_eof_error
May 4, 2026
Merged

vstinner merged 10 commits into
python:mainfrom
vstinner:ssl_got_eof_error

Conversation

@vstinner

@vstinner vstinner commented Apr 28, 2026 •

Copy link
Copy Markdown
Member

The _SSLSocket object now remembers if it gets an EOF error. In this case, read(), sendfile(), write() and do_handshake() method calls fail with SSLEOFError without calling the underlying OpenSSL function.

The _SSLSocket object now remembers if it gets an EOF error. In this
case, read(), sendfile() and write() method calls fail with
SSLEOFError without calling the underlying OpenSSL function.
@read-the-docs-community

read-the-docs-community Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32472356 | 📁 Comparing 0f650cc against main (2b6a137)

  🔍 Preview build  

2 files changed
± download.html
± whatsnew/changelog.html
Comment thread Modules/_ssl.c Resolved
Comment thread Lib/test/test_ssl.py Resolved
Comment thread Lib/test/test_ssl.py Resolved
Comment thread Lib/test/test_ssl.py Resolved
@@ -0,0 +1,7 @@
:mod:`ssl`: Update :class:`ssl.SSLSocket` for OpenSSL 4. The class now
remembers if it gets a :exc:`ssl.SSLEOFError`. In this case, following
:meth:`~ssl.SSLSocket.read`, :meth:`!sendfile`, :meth:`~ssl.SSLSocket.write`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:meth:~ssl.SSLSocket.sendfile ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using :meth:~ssl.SSLSocket.sendfile makes the documentation fails to build. It doesn't work since SSLSocket.sendfile() has no anchor at https://docs.python.org/dev/library/ssl.html#ssl.SSLSocket, but SSLSocket.sendfile() method is documented

@vstinner

Copy link
Copy Markdown
Member Author

@gpshead: Please review the updated PR.

Note: Before, I didn't want to use self.addCleanup(server.join) in the test since the server could hang. I added the timeout that you suggested on the socket and so the server should no longer hang on error.

Comment thread Lib/test/test_ssl.py Resolved
Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner

Copy link
Copy Markdown
Member Author

@picnixz: Would you mind to review this change?

It would be nice to have OpenSSL 4 support in Python 3.15 beta1 (feature freeze is next Tuesday).

@vstinner
vstinner merged commit 7b7fa3f into python:main May 4, 2026
50 checks passed
@vstinner
vstinner deleted the ssl_got_eof_error branch May 4, 2026 11:53
vstinner added a commit to vstinner/cpython that referenced this pull request May 13, 2026
The _SSLSocket object now remembers if it gets an EOF error. In this
case, read(), sendfile(), write() and do_handshake method calls fail
with SSLEOFError without calling the underlying OpenSSL function.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
(cherry picked from commit 7b7fa3f)
ziyao233 added a commit to ziyao233/eweos-packages that referenced this pull request Nov 24, 2026
@vstinner

Copy link
Copy Markdown
Member Author

This change adds PySSLSocket.got_eof_error member. I created openssl/openssl#30894 to ask if the OpenSSL 4 behavior change was made on purpose or not. The OpenSSL issue has been closed:

I am closing this issue because the use case is unclear and no clarification was provided for 7 months.

IMO Python has to remember if it got SSL_ERROR_EOF and no longer call OpenSSL if it's the case. So adding PySSLSocket.got_eof_error is the right design for Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants