This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_ssl: test_get_server_certificate() and test_msg_callback_deadlock_bpo43577() fail randomly on the macOS CI
Type: Stage: resolved
Components: Tests Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, erlendaasland, miss-islington, pablogsal, ronaldoussoren, terry.reedy, vstinner
Priority: high Keywords: patch

Created on 2021-05-25 07:24 by erlendaasland, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
5_Display build info.txt erlendaasland, 2021-05-26 07:57
Pull Requests
URL Status Linked Edit
PR 26893 merged erlendaasland, 2021-06-24 11:32
PR 26894 merged miss-islington, 2021-06-24 12:05
PR 26895 merged miss-islington, 2021-06-24 12:06
PR 26896 merged miss-islington, 2021-06-24 12:06
Messages (40)
msg394299 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-25 07:24
See https://github.com/python/cpython/pull/26104/checks?check_run_id=2662511684

======================================================================
ERROR: test_get_server_certificate (test.test_ssl.SimpleBackgroundTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/work/cpython/cpython/Lib/test/test_ssl.py", line 2132, in test_get_server_certificate
    _test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
  File "/Users/runner/work/cpython/cpython/Lib/test/test_ssl.py", line 2329, in _test_get_server_certificate
    pem = ssl.get_server_certificate((host, port), ca_certs=cert)
  File "/Users/runner/work/cpython/cpython/Lib/ssl.py", line 1520, in get_server_certificate
    with create_connection(addr, timeout=timeout) as sock:
  File "/Users/runner/work/cpython/cpython/Lib/socket.py", line 844, in create_connection
    raise err
  File "/Users/runner/work/cpython/cpython/Lib/socket.py", line 832, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused
msg394321 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-05-25 10:40
The problem could be related to bpo-43921. I neither have a macOS nor a Windows machine to reproduce and debug the issue. Since I'm cannot reproduce the problem on Linux, I'm unable to debug and fix it.
msg394339 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-05-25 12:54
>  I neither have a macOS nor a Windows machine to reproduce and debug the issue.

Can you maybe use a VM for Windows?
msg394341 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-25 13:03
I’ll see if I can provoke it on my Mac.

What’s the preferred solution?

1. Catch the connection failure and skip the test?
2. Retry connection?
3. Find the root cause and make sure it never ever happens :)

Maybe 2. is acceptable :)
msg394342 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-05-25 13:07
Is possible that these are flaky tests but I am afraid this may be something more important so o would prefer to go with 3 ;)
msg394344 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-25 13:16
I feared that ;)
msg394347 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-25 13:23
Getting there. The error message is similar:

$ ./python.exe -m test test_ssl -m test_get_server_certificate -u all -F
...
0:02:11 load avg: 2.10 [328] test_ssl
test test_ssl failed -- Traceback (most recent call last):
  File "/Users/erlendaasland/src/cpython-ssl/Lib/test/test_ssl.py", line 2132, in test_get_server_certificate
    _test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
  File "/Users/erlendaasland/src/cpython-ssl/Lib/test/test_ssl.py", line 2329, in _test_get_server_certificate
    pem = ssl.get_server_certificate((host, port), ca_certs=cert)
  File "/Users/erlendaasland/src/cpython-ssl/Lib/ssl.py", line 1521, in get_server_certificate
    with context.wrap_socket(sock, server_hostname=host) as sslsock:
  File "/Users/erlendaasland/src/cpython-ssl/Lib/ssl.py", line 518, in wrap_socket
    return self.sslsocket_class._create(
  File "/Users/erlendaasland/src/cpython-ssl/Lib/ssl.py", line 1070, in _create
    self.do_handshake()
  File "/Users/erlendaasland/src/cpython-ssl/Lib/ssl.py", line 1339, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [Errno 54] Connection reset by peer

test_ssl failed

== Tests result: FAILURE ==
msg394348 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-25 13:26
Got it:

0:02:29 load avg: 2.81 [389] test_ssl
test test_ssl failed -- Traceback (most recent call last):
  File "/Users/erlendaasland/src/cpython-ssl/Lib/test/test_ssl.py", line 2132, in test_get_server_certificate
    _test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
  File "/Users/erlendaasland/src/cpython-ssl/Lib/test/test_ssl.py", line 2329, in _test_get_server_certificate
    pem = ssl.get_server_certificate((host, port), ca_certs=cert)
  File "/Users/erlendaasland/src/cpython-ssl/Lib/ssl.py", line 1520, in get_server_certificate
    with create_connection(addr, timeout=timeout) as sock:
  File "/Users/erlendaasland/src/cpython-ssl/Lib/socket.py", line 844, in create_connection
    raise err
  File "/Users/erlendaasland/src/cpython-ssl/Lib/socket.py", line 832, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

test_ssl failed

== Tests result: FAILURE ==
msg394349 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-25 13:41
$ git diff
diff --git a/Lib/ssl.py b/Lib/ssl.py
index 2b131de043..9c281d8028 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -257,8 +257,9 @@ class _TLSMessageType:
 if sys.platform == "win32":
     from _ssl import enum_certificates, enum_crls
 
+from test.support import SHORT_TIMEOUT as _GLOBAL_DEFAULT_TIMEOUT
 from socket import socket, SOCK_STREAM, create_connection
-from socket import SOL_SOCKET, SO_TYPE, _GLOBAL_DEFAULT_TIMEOUT
+from socket import SOL_SOCKET, SO_TYPE
 import socket as _socket
 import base64        # for DER-to-PEM translation
 import errno

$ % ./python.exe -m test test_ssl -m test_get_server_certificate -u all -F
...
0:03:27 load avg: 2.24 [535] test_ssl
test test_ssl failed -- Traceback (most recent call last):
  File "/Users/erlendaasland/src/cpython-ssl/Lib/test/test_ssl.py", line 2132, in test_get_server_certificate
    _test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
  File "/Users/erlendaasland/src/cpython-ssl/Lib/test/test_ssl.py", line 2329, in _test_get_server_certificate
    pem = ssl.get_server_certificate((host, port), ca_certs=cert)
  File "/Users/erlendaasland/src/cpython-ssl/Lib/ssl.py", line 1521, in get_server_certificate
    with create_connection(addr, timeout=timeout) as sock:
  File "/Users/erlendaasland/src/cpython-ssl/Lib/socket.py", line 844, in create_connection
    raise err
  File "/Users/erlendaasland/src/cpython-ssl/Lib/socket.py", line 832, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

test_ssl failed

== Tests result: FAILURE ==
msg394355 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-05-25 14:17
Erlend, could you maybe add some context to the messages, unfortunately, I am failing to understand what they mean :(
msg394357 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-05-25 14:23
me, too. Did the change of import for timeout setting cause the issue?
msg394367 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-25 15:08
Yes, sorry ‘bout the cryptic messages :)

This is against current main branch (I’m not at my computer right now, so I don’t have the git ref). The first two failures came after 328 and 389 runs. Increasing the timeout (using test.support.SHORT_TIMEOUT) made it harder trigging the failure (~500 repetitions).

I’ll try to declutter when I’m back on my computer.
msg394418 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-26 07:26
New failure in CI: https://github.com/python/cpython/runs/2669949777?check_suite_focus=true

======================================================================
ERROR: test_msg_callback_deadlock_bpo43577 (test.test_ssl.TestSSLDebug)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/work/cpython/cpython/Lib/test/test_ssl.py", line 4813, in test_msg_callback_deadlock_bpo43577
    s.connect((HOST, server.port))
  File "/Users/runner/work/cpython/cpython/Lib/ssl.py", line 1372, in connect
    self._real_connect(addr, False)
  File "/Users/runner/work/cpython/cpython/Lib/ssl.py", line 1359, in _real_connect
    super().connect(addr)
ConnectionRefusedError: [Errno 61] Connection refused
msg394420 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-26 07:57
Build info for macOS CI attached.
msg394739 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-29 21:44
Here's the output when with test.support.verbose = True:

test_ssl: testing with 'OpenSSL 1.1.1k  25 Mar 2021' (1, 1, 1, 11, 15)                                                 
          under Mac ('11.3.1', ('', '', ''), 'x86_64')                                                                 
          HAS_SNI = True                                                                                               
          OP_ALL = 0x80000054                                                                                          
          OP_NO_TLSv1_1 = 0x10000000                                                                                   
test_get_server_certificate (test.test_ssl.SimpleBackgroundTests) ...  server:  new connection from ('127.0.0.1', 51163)

 server:  bad connection attempt from ('127.0.0.1', 51163):                                                            
Traceback (most recent call last):
   File "/Users/erlendaasland/src/cpython-ssl/Lib/test/test_ssl.py", line 2366, in wrap_conn                           
    self.sslconn = self.server.context.wrap_socket(
   File "/Users/erlendaasland/src/cpython-ssl/Lib/ssl.py", line 518, in wrap_socket                                    
    return self.sslsocket_class._create(
   File "/Users/erlendaasland/src/cpython-ssl/Lib/ssl.py", line 1070, in _create                                       
    self.do_handshake()
   File "/Users/erlendaasland/src/cpython-ssl/Lib/ssl.py", line 1339, in do_handshake                                  
    self._sslobj.do_handshake()
 OSError: [Errno 41] Protocol wrong type for socket                                                                    
ERROR

======================================================================                                                 
ERROR: test_get_server_certificate (test.test_ssl.SimpleBackgroundTests)                                               
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/erlendaasland/src/cpython-ssl/Lib/test/test_ssl.py", line 2130, in test_get_server_certificate          
    _test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
  File "/Users/erlendaasland/src/cpython-ssl/Lib/test/test_ssl.py", line 2327, in _test_get_server_certificate         
    pem = ssl.get_server_certificate((host, port), ca_certs=cert)
  File "/Users/erlendaasland/src/cpython-ssl/Lib/ssl.py", line 1520, in get_server_certificate
    with create_connection(addr, timeout=timeout) as sock:
  File "/Users/erlendaasland/src/cpython-ssl/Lib/socket.py", line 844, in create_connection                            
    raise err
  File "/Users/erlendaasland/src/cpython-ssl/Lib/socket.py", line 832, in create_connection                            
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

---------------------------------------------------------------------- 


The mock server fails with EPROTOTYPE, thus the client fails with connection refused.

I found similar issues after doing some googling:
- http://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
- https://github.com/benoitc/gunicorn/issues/1487#issuecomment-333680970

This might be the same macOS bug.
msg394741 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-05-29 22:23
> This might be the same macOS bug.

It could be, but the same thing happens on Windows
msg394751 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-30 06:37
> It could be, but the same thing happens on Windows

Are you sure? All the reports are from macOS CI. Christian mentioned that it could be similar to another ssl test failure that also happen on Windows, but those tracebacks do not match the ones in this issue.
msg394752 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-30 06:40
See also bpo-43855.
msg394798 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-31 09:12
FWIW:

1st shell:
$ ./python.exe -m test test_ssl -u all -m test_get_server_certificate -F
$ ps
[...]
 1271 ttys004    0:01.00 ./python.exe -m test test_ssl -u all -m test_get_server_certificate -F

2nd shell:
$ sudo errinfo -p 1271

The syscall trace shows that errno 41 is returned by write():
      python.exe            write   41  Protocol wrong type for socket 
      python.exe            ioctl   25  Inappropriate ioctl for device 
      python.exe            ioctl   25  Inappropriate ioctl for device 
      python.exe            ioctl   25  Inappropriate ioctl for device 
      python.exe            ioctl   25  Inappropriate ioctl for device 
      python.exe          connect   61  Connection refused 
      python.exe          connect   61  Connection refused 
      python.exe            ioctl   25  Inappropriate ioctl for device 
      python.exe            ioctl   25  Inappropriate ioctl for device 
      python.exe            ioctl   25  Inappropriate ioctl for device 
      python.exe            ioctl   25  Inappropriate ioctl for device 
      python.exe           stat64    2  No such file or directory
msg394805 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-05-31 12:12
> Are you sure? All the reports are from macOS CI. Christian mentioned that it could be similar to another ssl test failure that also happen on Windows, but those tracebacks do not match the ones in this issue.

I am certainly not sure, but I think they are related.
msg396149 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-06-19 19:42
See #44237 for another repeatedly failing (false positive) ssl test.  These and other randomly failing tests should be skipped for routine CI regression testing of PRs.
msg396425 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-06-23 14:56
Two GHI test macOS failures yesterday, once on main, this is on 3.10 backport
https://github.com/python/cpython/pull/26850/checks?check_run_id=2885797677

ERROR: test_get_server_certificate (test.test_ssl.SimpleBackgroundTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/work/cpython/cpython/Lib/test/test_ssl.py", line 2180, in test_get_server_certificate
    _test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
  File "/Users/runner/work/cpython/cpython/Lib/test/test_ssl.py", line 2377, in _test_get_server_certificate
    pem = ssl.get_server_certificate((host, port), ca_certs=cert)
  File "/Users/runner/work/cpython/cpython/Lib/ssl.py", line 1527, in get_server_certificate
    with create_connection(addr, timeout=timeout) as sock:
  File "/Users/runner/work/cpython/cpython/Lib/socket.py", line 844, in create_connection
    raise err
  File "/Users/runner/work/cpython/cpython/Lib/socket.py", line 832, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

So far reported (including #44237) ConnectionRefusedError in
test_get_server_certificate X many
test_msg_callback_deadlock_bpo43577
test_get_server_certificate_sni

ConnectionResetError: 
test_connect_cadata

Please, please, skip the randomly failing tests, as is done for other modules.  This has been going on a month now.  It waste other people's time, making merging more painful.
msg396431 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-23 16:09
Although I simphatise with the frustration and I would really like to skip them myself, as a release manager I am quite concerned that skip them would masks an actual regression, as these failures are not present in previous versions.
msg396436 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-23 17:35
Has these issues (ConnectionRefusedError/ConnectionResetError during handshake) been reported on other systems than macOS? AFAICS, they've only been reported for the macOS CI.
msg396438 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-23 18:30
Only on MacOS afaik
msg396441 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-23 19:01
See also bpo-33450.
msg396464 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-24 09:39
Using this patch, I'm (so far) no longer able to reproduce these test failures:

diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index cee97a8302..c9c1546467 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -2443,9 +2443,13 @@ def wrap_conn(self):
                 self.server.conn_errors.append(str(e))
                 if self.server.chatty:
                     handle_error("\n server:  bad connection attempt from " + repr(self.addr) + ":\n")
-                self.running = False
-                self.server.stop()
-                self.close()
+
+                # bpo-44229, bpo-43855, bpo-44237, and bpo-33450:
+                # Ignore spurious EPROTOTYPE returned by write() on macOS.
+                if e.errno != errno.EPROTOTYPE and sys.platform != "darwin":
+                    self.running = False
+                    self.server.stop()
+                    self.close()
                 return False
             else:
                 self.server.shared_ciphers.append(self.sslconn.shared_ciphers())



Running for 40 minutes now, right now passing 6k iterations for test_get_server_certificate, test_msg_callback_deadlock_bpo43577, and test_get_server_certificate_sni.
msg396466 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-24 09:43
... should perhaps also return True in that case, but it does not seem to have any thing to say.
msg396471 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-24 11:28
I can reproduce these issues easily on 3.7, 3.8, and 3.9:

$ python3.7 -m test test_ssl -u all -F -m test_get_server_certificate -v
[...]
test_get_server_certificate (test.test_ssl.SimpleBackgroundTests) ...  server:  new connection from ('127.0.0.1', 57294)

 server:  bad connection attempt from ('127.0.0.1', 57294):
Traceback (most recent call last):
   File "/Users/erlendaasland/install/lib/python3.7/test/test_ssl.py", line 2313, in wrap_conn
    self.sock, server_side=True)
   File "/Users/erlendaasland/install/lib/python3.7/ssl.py", line 423, in wrap_socket
    session=session
   File "/Users/erlendaasland/install/lib/python3.7/ssl.py", line 870, in _create
    self.do_handshake()
   File "/Users/erlendaasland/install/lib/python3.7/ssl.py", line 1139, in do_handshake
    self._sslobj.do_handshake()
 OSError: [Errno 41] Protocol wrong type for socket
ERROR

======================================================================
ERROR: test_get_server_certificate (test.test_ssl.SimpleBackgroundTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/erlendaasland/install/lib/python3.7/test/test_ssl.py", line 2108, in test_get_server_certificate
    _test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
  File "/Users/erlendaasland/install/lib/python3.7/test/test_ssl.py", line 2273, in _test_get_server_certificate
    pem = ssl.get_server_certificate((host, port), ca_certs=cert)
  File "/Users/erlendaasland/install/lib/python3.7/ssl.py", line 1313, in get_server_certificate
    with  create_connection(addr) as sock:
  File "/Users/erlendaasland/install/lib/python3.7/socket.py", line 728, in create_connection
    raise err
  File "/Users/erlendaasland/install/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused


$ python3.8 -m test test_ssl -u all -F -m test_get_server_certificate -v
test_ssl: testing with 'OpenSSL 1.1.1k  25 Mar 2021' (1, 1, 1, 11, 15)
          under Mac ('10.16', ('', '', ''), 'x86_64')
          HAS_SNI = True
          OP_ALL = 0x80000054
          OP_NO_TLSv1_1 = 0x10000000
test_get_server_certificate (test.test_ssl.SimpleBackgroundTests) ...  server:  new connection from ('127.0.0.1', 59370)

 server:  bad connection attempt from ('127.0.0.1', 59370):
Traceback (most recent call last):
   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/test/test_ssl.py", line 2348, in wrap_conn
    self.sslconn = self.server.context.wrap_socket(
   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
 OSError: [Errno 41] Protocol wrong type for socket
ERROR

======================================================================
ERROR: test_get_server_certificate (test.test_ssl.SimpleBackgroundTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/test/test_ssl.py", line 2142, in test_get_server_certificate
    _test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/test/test_ssl.py", line 2309, in _test_get_server_certificate
    pem = ssl.get_server_certificate((host, port), ca_certs=cert)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1484, in get_server_certificate
    with context.wrap_socket(sock) as sslsock:
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [Errno 54] Connection reset by peer


$ python3.9 -m test test_ssl -u all -F -m test_get_server_certificate -v
[...]
test_ssl: testing with 'OpenSSL 1.1.1k  25 Mar 2021' (1, 1, 1, 11, 15)
          under Mac ('10.16', ('', '', ''), 'x86_64')
          HAS_SNI = True
          OP_ALL = 0x80000054
          OP_NO_TLSv1_1 = 0x10000000
test_get_server_certificate (test.test_ssl.SimpleBackgroundTests) ...  server:  new connection from ('127.0.0.1', 60096)

 server:  bad connection attempt from ('127.0.0.1', 60096):
Traceback (most recent call last):
   File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/test/test_ssl.py", line 2353, in wrap_conn
    self.sslconn = self.server.context.wrap_socket(
   File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
   File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create
    self.do_handshake()
   File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
 OSError: [Errno 41] Protocol wrong type for socket
ERROR

======================================================================
ERROR: test_get_server_certificate (test.test_ssl.SimpleBackgroundTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/test/test_ssl.py", line 2147, in test_get_server_certificate
    _test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/test/test_ssl.py", line 2314, in _test_get_server_certificate
    pem = ssl.get_server_certificate((host, port), ca_certs=cert)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1484, in get_server_certificate
    with context.wrap_socket(sock) as sslsock:
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [Errno 54] Connection reset by peer


It does not seem to be specific to 3.10/3.11.
msg396474 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-24 12:05
New changeset b5a52eef67997246b4235b5407e52a01e822ce56 by Erlend Egeberg Aasland in branch 'main':
bpo-44229: Ignore spurious EPROTOTYPE on macOS in test_ssl (GH-26893)
https://github.com/python/cpython/commit/b5a52eef67997246b4235b5407e52a01e822ce56
msg396479 - (view) Author: miss-islington (miss-islington) Date: 2021-06-24 12:25
New changeset 0796e21fea31fe7b697d84c8d03186817792c458 by Miss Islington (bot) in branch '3.9':
bpo-44229: Ignore spurious EPROTOTYPE on macOS in test_ssl (GH-26893)
https://github.com/python/cpython/commit/0796e21fea31fe7b697d84c8d03186817792c458
msg396481 - (view) Author: miss-islington (miss-islington) Date: 2021-06-24 12:27
New changeset b3fac2926b23b4f1342099e591aa3fed7f16876d by Miss Islington (bot) in branch '3.10':
bpo-44229: Ignore spurious EPROTOTYPE on macOS in test_ssl (GH-26893)
https://github.com/python/cpython/commit/b3fac2926b23b4f1342099e591aa3fed7f16876d
msg396482 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-24 12:28
Marking bpo-43855 as a duplicate of this issue.
msg396485 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-24 12:29
Marking bpo-44237 as a duplicate of this issue.
msg396487 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-24 12:57
FYI, here's a CI failure against 3.9:
https://github.com/python/cpython/runs/2894813367?check_suite_focus=true
msg396490 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-24 14:34
New changeset 71ba16b21cb35923098026117b5e6d823c5f5707 by Miss Islington (bot) in branch '3.8':
bpo-44229: Ignore spurious EPROTOTYPE on macOS in test_ssl (GH-26893) (GH-26895)
https://github.com/python/cpython/commit/71ba16b21cb35923098026117b5e6d823c5f5707
msg396580 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-27 14:17
I haven't observed this issue on the CI since GH-26893 through GH-26896 was merged. Marking this as resolved. If anyone disagrees, feel free to reopen :)
msg396613 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-06-28 08:01
http://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/ says:

"If we trigger a send while the kernel is in the middle of tearing down the socket, it returns EPROTOTYPE." (instead of ECONNRESET)

Maybe send() could raise a ConnectionResetError exception on EPROTOTYPE?
msg396615 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-28 08:05
But here, it is write() that returns EPROTOTYPE. See msg394798.
msg396616 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-06-28 08:11
I'd be interested in hearing Ronald's opinion. (Added to nosy.)
History
Date User Action Args
2022-04-11 14:59:46adminsetgithub: 88395
2021-06-28 08:11:11erlendaaslandsetnosy: + ronaldoussoren
messages: + msg396616
2021-06-28 08:05:05erlendaaslandsetmessages: + msg396615
2021-06-28 08:01:51vstinnersetnosy: + vstinner
messages: + msg396613
2021-06-27 14:17:20erlendaaslandsetstatus: open -> closed
resolution: fixed
messages: + msg396580

stage: patch review -> resolved
2021-06-24 14:34:42pablogsalsetmessages: + msg396490
2021-06-24 12:57:16erlendaaslandsetmessages: + msg396487
2021-06-24 12:29:31erlendaaslandsetmessages: + msg396485
2021-06-24 12:29:09erlendaaslandunlinkissue44237 dependencies
2021-06-24 12:29:09erlendaaslandlinkissue44237 superseder
2021-06-24 12:28:08erlendaaslandsetmessages: + msg396482
2021-06-24 12:27:43miss-islingtonsetmessages: + msg396481
2021-06-24 12:27:43erlendaaslandlinkissue43855 superseder
2021-06-24 12:25:49miss-islingtonsetmessages: + msg396479
2021-06-24 12:06:13miss-islingtonsetpull_requests: + pull_request25472
2021-06-24 12:06:07miss-islingtonsetpull_requests: + pull_request25471
2021-06-24 12:05:59miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25470
2021-06-24 12:05:49pablogsalsetmessages: + msg396474
2021-06-24 11:32:59erlendaaslandsetkeywords: + patch
stage: patch review
pull_requests: + pull_request25469
2021-06-24 11:28:47erlendaaslandsetmessages: + msg396471
versions: + Python 3.8, Python 3.9, Python 3.10
2021-06-24 09:43:06erlendaaslandsetmessages: + msg396466
2021-06-24 09:39:40erlendaaslandsetmessages: + msg396464
2021-06-23 19:01:36erlendaaslandsetmessages: + msg396441
2021-06-23 18:30:10pablogsalsetmessages: + msg396438
2021-06-23 17:35:57erlendaaslandsetmessages: + msg396436
2021-06-23 16:09:56pablogsalsetmessages: + msg396431
2021-06-23 14:56:36terry.reedysetpriority: normal -> high

messages: + msg396425
2021-06-19 19:42:15terry.reedysetnosy: + terry.reedy
messages: + msg396149
2021-06-03 01:52:59vstinnersettitle: Intermittent connection errors in ssl tests on macOS CI -> test_ssl: test_get_server_certificate() and test_msg_callback_deadlock_bpo43577() fail randomly on the macOS CI
2021-05-31 12:12:50pablogsalsetmessages: + msg394805
2021-05-31 09:12:45erlendaaslandsetmessages: + msg394798
2021-05-30 06:40:00erlendaaslandsetmessages: + msg394752
2021-05-30 06:37:13erlendaaslandsetmessages: + msg394751
2021-05-29 22:23:06pablogsalsetmessages: + msg394741
2021-05-29 21:44:55erlendaaslandsetmessages: + msg394739
2021-05-26 07:57:19erlendaaslandsetfiles: + 5_Display build info.txt

messages: + msg394420
2021-05-26 07:26:23erlendaaslandsetmessages: + msg394418
title: test_get_server_certificate fails intermittently on macOS -> Intermittent connection errors in ssl tests on macOS CI
2021-05-25 20:29:06christian.heimeslinkissue44237 dependencies
2021-05-25 15:08:24erlendaaslandsetmessages: + msg394367
2021-05-25 14:23:11christian.heimessetmessages: + msg394357
2021-05-25 14:17:52pablogsalsetmessages: + msg394355
2021-05-25 13:41:51erlendaaslandsetmessages: + msg394349
2021-05-25 13:26:37erlendaaslandsetmessages: + msg394348
2021-05-25 13:23:10erlendaaslandsetmessages: + msg394347
2021-05-25 13:16:27erlendaaslandsetmessages: + msg394344
2021-05-25 13:07:40pablogsalsetmessages: + msg394342
2021-05-25 13:03:56erlendaaslandsetmessages: + msg394341
2021-05-25 12:54:22pablogsalsetmessages: + msg394339
2021-05-25 10:40:47christian.heimessetmessages: + msg394321
2021-05-25 10:29:17erlendaaslandsetnosy: + pablogsal
2021-05-25 07:25:33erlendaaslandsettitle: test_get_server_certificate fails on macOS -> test_get_server_certificate fails intermittently on macOS
2021-05-25 07:24:56erlendaaslandcreate