[issue33090] race condition between send and recv in _ssl with non-zero timeout

Ronald Oussoren report at bugs.python.org
Fri Oct 23 05:12:37 EDT 2020


Ronald Oussoren <ronaldoussoren at mac.com> added the comment:

The script still fails on macOS 10.15 with python 3.9 (installed from python.org).

Interestingly enough:
- First run of the script worked without any problems
- Subsequent runs failed with various errors:

$ python3.9 t.py
Got connection from ('127.0.0.1', 60640)
Exception in thread ReadThread:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 950, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 888, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/ronald/Projects/python/github/cpython-ronald/t.py", line 93, in read_thread
    csocket.recv()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1226, in recv
    return self.read(buflen)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1101, in read
    return self._sslobj.read(len)
BlockingIOError: [Errno 35] Resource temporarily unavailable


----

Got connection from ('127.0.0.1', 60651)
.Traceback (most recent call last):
  File "/Users/ronald/Projects/python/github/cpython-ronald/t.py", line 74, in server_thread
Exception in thread WriteThread:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 950, in _bootstrap_inner
Exception in thread ReadThread:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 950, in _bootstrap_inner
    deal_with_client(newsocket)
  File "/Users/ronald/Projects/python/github/cpython-ronald/t.py", line 68, in deal_with_client
    data = connstream.read()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1101, in read
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 888, in run
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 888, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/ronald/Projects/python/github/cpython-ronald/t.py", line 93, in read_thread
    self._target(*self._args, **self._kwargs)
  File "/Users/ronald/Projects/python/github/cpython-ronald/t.py", line 89, in write_thread
    return self._sslobj.read(len)
    csocket.recv()
ssl.SSLError: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2621)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1226, in recv
    csocket.send(b'blah')
Closed connection from ('127.0.0.1', 60651)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1173, in send
    return self.read(buflen)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1101, in read
    return self._sslobj.write(data)
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:2471)
    return self._sslobj.read(len)
ssl.SSLError: [SSL: SSLV3_ALERT_BAD_RECORD_MAC] sslv3 alert bad record mac (_ssl.c:2621)

----

Got connection from ('127.0.0.1', 60636)
.Exception in thread ReadThread:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 950, in _bootstrap_inner
Traceback (most recent call last):
  File "/Users/ronald/Projects/python/github/cpython-ronald/t.py", line 74, in server_thread
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 888, in run
    deal_with_client(newsocket)
  File "/Users/ronald/Projects/python/github/cpython-ronald/t.py", line 68, in deal_with_client
    self._target(*self._args, **self._kwargs)
  File "/Users/ronald/Projects/python/github/cpython-ronald/t.py", line 93, in read_thread
    csocket.recv()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1226, in recv
    data = connstream.read()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1101, in read
    return self.read(buflen)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1101, in read
    return self._sslobj.read(len)
    return self._sslobj.read(len)
ssl.SSLError: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2621)
Closed connection from ('127.0.0.1', 60636)
BlockingIOError: [Errno 35] Resource temporarily unavailable
Exception in thread WriteThread:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 950, in _bootstrap_inner

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33090>
_______________________________________


More information about the Python-bugs-list mailing list