Skip to content

Commit 0222334

Browse files
committed
fix: make proxy robust to raw sockets and mocks in unit tests
1 parent fb6449f commit 0222334

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎google/cloud/sql/connector/psycopg.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ def forward_pending() -> bool:
3737
"""Read any pending decrypted data from SSL buffer and forward it.
3838
Returns True if EOF was reached or error occurred (should exit).
3939
"""
40-
while remote.pending() > 0:
40+
if not hasattr(remote, "pending"):
41+
return False
42+
try:
43+
pending_bytes = remote.pending()
44+
except AttributeError:
45+
return False
46+
if not isinstance(pending_bytes, int):
47+
return False
48+
49+
while pending_bytes > 0:
4150
try:
4251
data = remote.recv(8192)
4352
except OSError as e:
@@ -51,6 +60,12 @@ def forward_pending() -> bool:
5160
except OSError as e:
5261
logger.debug("psycopg proxy: local send pending error: %s", e)
5362
return True
63+
try:
64+
pending_bytes = remote.pending()
65+
except (AttributeError, OSError):
66+
break
67+
if not isinstance(pending_bytes, int):
68+
break
5469
return False
5570

5671
try:

0 commit comments

Comments
 (0)