Skip to content

3.15.0a8 fails test_urllib2_localnet with OpenSSL 4.0.0beta1 #148292

Closed

Description

@hroncok

Bug report

Bug description:

When building Python 3.15.0a8 with OpenSSL 4.0.0beta1, which has just landed in Fedora Rawhide (not yet on the mirrors, only in the buildroot), we see the following test failures:

======================================================================
ERROR: test_https (test.test_urllib2_localnet.TestUrlopen.test_https)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/test/test_urllib2_localnet.py", line 569, in test_https
    data = self.urlopen("https://localhost:%s/bizarre" % handler.port, context=context)
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/test/test_urllib2_localnet.py", line 473, in urlopen
    l.extend(f.readlines(200))
             ~~~~~~~~~~~^^^^^
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/http/client.py", line 714, in readline
    result = self.fp.readline(limit)
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/socket.py", line 734, in readinto
    return self._sock.recv_into(b)
           ~~~~~~~~~~~~~~~~~~~~^^^
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/ssl.py", line 1355, in recv_into
    return self.read(nbytes, buffer)
           ~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/ssl.py", line 1154, in read
    return self._sslobj.read(len, buffer)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
ssl.SSLError: A failure in the SSL library occurred (_ssl.c:2982)
======================================================================
ERROR: test_https_sni (test.test_urllib2_localnet.TestUrlopen.test_https_sni)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/test/test_urllib2_localnet.py", line 585, in test_https_sni
    self.urlopen("https://localhost:%s" % handler.port, context=context)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/test/test_urllib2_localnet.py", line 473, in urlopen
    l.extend(f.readlines(200))
             ~~~~~~~~~~~^^^^^
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/http/client.py", line 714, in readline
    result = self.fp.readline(limit)
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/socket.py", line 734, in readinto
    return self._sock.recv_into(b)
           ~~~~~~~~~~~~~~~~~~~~^^^
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/ssl.py", line 1355, in recv_into
    return self.read(nbytes, buffer)
           ~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/python3.15-3.15.0_a8-build/Python-3.15.0a8/Lib/ssl.py", line 1154, in read
    return self._sslobj.read(len, buffer)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
ssl.SSLError: A failure in the SSL library occurred (_ssl.c:2982)
----------------------------------------------------------------------
Ran 2 tests in 0.142s
FAILED (errors=2)

Considering #146207 is closed, I thought I better let you know.

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Apr 9, 2026
  2. hugovk commented on Apr 9, 2026

    @hugovk
    Member

    This can be reproduced on our CI with hugovk@4e9bb25:

    #146217 added some initial support for 4.0.0-alpha1, but more is needed.

  3. vstinner commented on Apr 9, 2026

    @vstinner
    Member

    I noticed these test failures (test_urllib2_localnet) when testing OpenSSL 4.0.0 alpha 1 and I wrote a patch fixing them: #146217 (comment). I didn't merge this change since I'm not confident that my change makes sense/is correct.

    It seems like OpenSSL 4 behaves differently than OpenSSL 3 when reaching EOF.

    cc @picnixz @gpshead @dstufft @alex

  4. vstinner commented on Apr 9, 2026

    @vstinner
    Member

    I can reproduce the issue on Fedora 43 with commands:

    python3 Tools/ssl/multissltests.py --steps=library --base-directory "$HOME/multissl" --openssl 4.0.0 --system Linux
    export LD_LIBRARY_PATH=$HOME/multissl/openssl/4.0.0/lib64
    ./configure --with-pydebug --with-openssl=$HOME/multissl/openssl/4.0.0/
    make
    ./python -m test -v test_urllib2_localnet -u all -v
    

    UPDATE: I updated instructions for OpenSSL 4.0.0 final.

  5. picnixz commented on Apr 9, 2026

    @picnixz
    Member

    I quickly glanced at the different errors we had and it appears we are hitting this path in PySSL_SetError with OpenSSL 4.x:

            case SSL_ERROR_SSL:
            {
                p = PY_SSL_ERROR_SSL;
                if (e == 0) {
                    /* possible? */
                    errstr = "A failure in the SSL library occurred";
                }
    

    This means that we had some SSL error (SSL_ERROR_SSL) but ERR_peek_last_error did not set an error code. This can be done for various reasons: either they forgot to update something, or another path is being taken. The way we propagate SSL errors is a bit messy but we may have missed one call. Ideally, we should know the exact code path that was taken and to see why ERR_peek_last_error() returned 0 (it's the value of e above).

  6. vstinner commented on Apr 9, 2026

    @vstinner
    Member

    I didn't update Modules/_ssl_data*.h for OpenSSL 4 in my first change for alpha 1.

  7. picnixz commented on Apr 9, 2026

    @picnixz
    Member

    I don't think the problem would be mnemonics here (though we can try to see what happens if we do an update). What's surprising is ERR_peek_last_error returns 0 (this is an OSSL function). It may be because we are incorrectly calling it at a point where there is no more an error though.

  8. added 5 commits that reference this issue on Apr 15, 2026
  9. added 2 commits that reference this issue on May 4, 2026
  10. added 2 commits that reference this issue on May 13, 2026
  11. vstinner commented on May 26, 2026

    @vstinner
    Member

    The issue is now fixed in 3.15 and main branches. Thanks for the bug report.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions