Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_ssl logs a traceback #75501

Closed
vstinner opened this issue Sep 1, 2017 · 9 comments
Closed

test_ssl logs a traceback #75501

vstinner opened this issue Sep 1, 2017 · 9 comments
Labels
3.7 (EOL) end of life tests Tests in the Lib/test dir

Comments

@vstinner
Copy link
Member

vstinner commented Sep 1, 2017

BPO 31320
Nosy @pitrou, @vstinner, @tiran, @alex, @vadmium, @dstufft, @Mariatta
PRs
  • bpo-31320: No traceback to sys.stderr in test_ssl #3360
  • [3.6] bpo-31320: No traceback to sys.stderr in test_ssl (GH-3360) #3369
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-09-13.00:54:27.421>
    created_at = <Date 2017-09-01.14:39:37.775>
    labels = ['3.7', 'tests']
    title = 'test_ssl logs a traceback'
    updated_at = <Date 2017-09-13.00:54:27.420>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2017-09-13.00:54:27.420>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-09-13.00:54:27.421>
    closer = 'vstinner'
    components = ['Tests']
    creation = <Date 2017-09-01.14:39:37.775>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31320
    keywords = []
    message_count = 9.0
    messages = ['301107', '301108', '301110', '301119', '301209', '301375', '301403', '301425', '302020']
    nosy_count = 8.0
    nosy_names = ['janssen', 'pitrou', 'vstinner', 'christian.heimes', 'alex', 'martin.panter', 'dstufft', 'Mariatta']
    pr_nums = ['3360', '3369']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue31320'
    versions = ['Python 3.6', 'Python 3.7']

    @vstinner
    Copy link
    Member Author

    vstinner commented Sep 1, 2017

    It would be nice to not log such traceback:

    haypo@selma$ ./python -m test test_ssl -m test.test_ssl.ThreadedTests.test_echo
    Run tests sequentially
    0:00:00 load avg: 0.69 [1/1] test_ssl
    Exception in thread Thread-16:
    Traceback (most recent call last):
      File "/home/haypo/prog/python/master/Lib/threading.py", line 917, in _bootstrap_inner
        self.run()
      File "/home/haypo/prog/python/master/Lib/test/test_ssl.py", line 1936, in run
        if not self.wrap_conn():
      File "/home/haypo/prog/python/master/Lib/test/test_ssl.py", line 1881, in wrap_conn
        self.sock, server_side=True)
      File "/home/haypo/prog/python/master/Lib/ssl.py", line 401, in wrap_socket
        _context=self, _session=session)
      File "/home/haypo/prog/python/master/Lib/ssl.py", line 808, in __init__
        self.do_handshake()
      File "/home/haypo/prog/python/master/Lib/ssl.py", line 1061, in do_handshake
        self._sslobj.do_handshake()
      File "/home/haypo/prog/python/master/Lib/ssl.py", line 683, in do_handshake
        self._sslobj.do_handshake()
    OSError: [Errno 0] Error

    1 test OK.

    Total duration: 205 ms
    Tests result: SUCCESS

    @vstinner vstinner added 3.7 (EOL) end of life tests Tests in the Lib/test dir labels Sep 1, 2017
    @vstinner
    Copy link
    Member Author

    vstinner commented Sep 1, 2017

    Python 2.7 doesn't seem to be affected.

    @pitrou
    Copy link
    Member

    pitrou commented Sep 1, 2017

    I don't get such traceback here (Ubuntu 16.04, OpenSSL 1.0.2g).

    @vstinner
    Copy link
    Member Author

    vstinner commented Sep 1, 2017

    I'm running Fedora 26:

    haypo@selma$ ./python -m test.pythoninfo|grep -E 'ssl|platform'
    platform.architecture: 32bit ELF
    platform.platform: Linux-4.12.5-300.fc26.x86_64-x86_64-with-fedora-26-Twenty_Six
    platform.python_implementation: CPython
    ssl.HAS_SNI: True
    ssl.OPENSSL_VERSION: OpenSSL 1.1.0f-fips 25 May 2017
    ssl.OPENSSL_VERSION_INFO: (1, 1, 0, 6, 15)
    ssl.OP_ALL: -0x7fffffac
    ssl.OP_NO_TLSv1_1: 0x10000000
    sys.platform: linux

    @vadmium
    Copy link
    Member

    vadmium commented Sep 4, 2017

    Not sure if you just want to hide the presence of the exception and traceback. But regarding the exception itself (OSError with errno 0), this is not ideal. From memory, you tend to get this when the connection is shut down insecurely at the TCP level. A better exception would be SSLEOFError. Similar report in bpo-31122 (same wrap_socket → do_handshake chain). Probably also relevant: bpo-10808.

    @tiran
    Copy link
    Member

    tiran commented Sep 5, 2017

    The error occurs in the test case that uses a PROTOCOL_TLS_SERVER context for both client and server context. In that case, OpenSSL wrap_socket() fails internally and OpenSSL raises an OSError with errno 0.

    Simple fix: catch OSError in the client thread and fail the test appropriately.

    @tiran
    Copy link
    Member

    tiran commented Sep 5, 2017

    New changeset 305e56c by Christian Heimes in branch 'master':
    bpo-31320: No traceback to sys.stderr in test_ssl (bpo-3360)
    305e56c

    @Mariatta
    Copy link
    Member

    Mariatta commented Sep 6, 2017

    New changeset c506403 by Mariatta (Miss Islington (bot)) in branch '3.6':
    [3.6] bpo-31320: No traceback to sys.stderr in test_ssl (GH-3360) (GH-3369)
    c506403

    @vstinner
    Copy link
    Member Author

    Thanks for the fix Christian.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life tests Tests in the Lib/test dir
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants