Skip to content

Commit

Permalink
Fix WantReadError for Azure instances
Browse files Browse the repository at this point in the history
Issue #158
The problem was that not entire server response was consumed. Azure response consists of 2 packets, while local server response fits in 1 packet and code was reading only first packet of the response.
  • Loading branch information
denisenkom committed Jan 22, 2024
1 parent 7043de8 commit 14b0284
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/pytds/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,18 @@ def establish_channel(tds_sock: _TdsSession) -> None:
w.write(req)
w.flush()
logger.debug("receiving response from the server")
r.begin_response()
resp = r.read_whole_packet()
# TODO validate r.packet_type
logger.debug(
"adding %d bytes of the response into the TLS connection buffer",
len(resp),
)
conn.bio_write(resp)
resp_meta = r.begin_response()
if resp_meta.type != tds_base.PacketType.PRELOGIN:
raise tds_base.Error(
f"Invalid packet type was received from server, expected PRELOGIN(18) got {resp_meta.type}"
)
while not r.stream_finished():
resp = r.recv(4096)
logger.debug(
"adding %d bytes of the response into the TLS connection buffer",
len(resp),
)
conn.bio_write(resp)
else:
logger.info("TLS handshake is complete")
if login.validate_host:
Expand Down
2 changes: 1 addition & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
default_user = conf["sqluser"]
default_password = conf["sqlpassword"]
default_use_mars = conf["use_mars"]
default_auth = conf["auth"]
default_auth = conf.get("auth")
default_cafile = conf.get("cafile")
else:
default_host = None
Expand Down

0 comments on commit 14b0284

Please sign in to comment.