denisenkom / pytds

Python DBAPI driver for MSSQL using pure Python TDS (Tabular Data Stream) protocol implementation
MIT License
191 stars 53 forks source link

Exception while handling WantReadError in v1.14.0 #158

Closed terratrue-daniel closed 9 months ago

terratrue-daniel commented 10 months ago

Started running into an issue in v1.14.0 that I didn't see in v1.13.0:

  File "<redacted>/venv/lib/python3.10/site-packages/pytds/tls.py", line 172, in establish_channel
    conn.do_handshake()
  File "<redacted>/venv/lib/python3.10/site-packages/OpenSSL/SSL.py", line 2202, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "<redacted>/venv/lib/python3.10/site-packages/OpenSSL/SSL.py", line 1810, in _raise_ssl_error
    raise WantReadError()
OpenSSL.SSL.WantReadError

During handling of the above exception, another exception occurred:

  ...
  File "<redacted>/venv/lib/python3.10/site-packages/pytds/tls.py", line 190, in establish_channel
    r.begin_response()
  File "<redacted>/venv/lib/python3.10/site-packages/pytds/tds_reader.py", line 198, in begin_response
    raise RuntimeError(
RuntimeError: begin_response was called before previous response was fully consumed

I saw that this line was recently introduced as part of a refactor. But I don't fully understand why it needed to be added.

denisenkom commented 10 months ago

Thank you for reporting. I wasn't able to reproduce this issue in my environment. Can you provide steps to reproduce?

tmeckel commented 10 months ago

@denisenkom experiencing the same error with the latest release of PyTDS. Trying to connect to an Azure SQL Instance. The code runs flawlessly in a local dev environment using a containerized version of SQL Server 2017.

Traceback (most recent call last):
File "/app/site-packages/pytds/tls.py", line 172, in establish_channel
conn.do_handshake()
File "/app/site-packages/OpenSSL/SSL.py", line 2202, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/app/site-packages/OpenSSL/SSL.py", line 1810, in _raise_ssl_error
raise WantReadError()
OpenSSL.SSL.WantReadError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/site-packages/pytds/utils.py", line 36, in exponential_backoff
return work(try_time)
File "/app/site-packages/pytds/__init__.py", line 358, in attempt
return _connect(
File "/app/site-packages/pytds/__init__.py", line 454, in _connect
route = tds_socket.login()
File "/app/site-packages/pytds/tds_socket.py", line 90, in login
self._main_session.process_prelogin(self._login)
File "/app/site-packages/pytds/tds_session.py", line 1277, in process_prelogin
self.parse_prelogin(octets=p, login=login)
File "/app/site-packages/pytds/tds_session.py", line 1329, in parse_prelogin
tls.establish_channel(self)
File "/app/site-packages/pytds/tls.py", line 190, in establish_channel
r.begin_response()
File "/app/site-packages/pytds/tds_reader.py", line 198, in begin_response
raise RuntimeError(
RuntimeError: begin_response was called before previous response was fully consumed
terratrue-daniel commented 10 months ago

Thank you for reporting. I wasn't able to reproduce this issue in my environment. Can you provide steps to reproduce?

I receive this error when I try to connect to a SQL Server instance set up in Azure. pytds is being consumed via SQLAlchemy. Let me know if there's anything specific you need to know about the SQL Server instance -- it seems to only affect Azure since I have not encountered this issue when it's deployed in GCP or RDS.

tmeckel commented 10 months ago

@denisenkom pinning python-tds to 1.13.0 solved the issue. Must be definitely something with 1.14.0

denisenkom commented 10 months ago

I will try testing with Azure

denisenkom commented 10 months ago

Fix is ready, pending release of a new version

denisenkom commented 9 months ago

Fix released in 1.15.0