You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No exception thrown and no timeout when using a Connector that is closed #1268
No exception thrown and no timeout when using a Connector that is closed, code stays stuck waiting
Example code (or command)
importosfromgoogle.cloud.sql.connectorimportConnectorfromsqlalchemyimportcreate_engineos.environ['GOOGLE_APPLICATION_CREDENTIALS'] ='service-account.json'connector=Connector()
defget_iam_connection():
"""Establish connection using IAM authentication."""returnconnector.connect(
"unix-socket",
"pg8000",
ip_type="public",
db="dbname",
user="dbuser",
enable_iam_auth=True,
)
engine=create_engine(
"postgresql+pg8000://",
creator=lambda: get_iam_connection(),
pool_size=5,
max_overflow=2,
pool_timeout=10,
pool_recycle=1800,
connect_args={"use_native_uuid": False},
)
# Intentionally close the connector before it's usedconnector.close()
# It gets stuck waiting on the line belowwithengine.connect() asconn:
# The line below this one is never called, it's stuck on the line above.result=conn.execute(text("SELECT version()")).fetchone()
print(f"Connection successful. Database version: {result[0]}")
Steps to reproduce?
Close the connection intentionally (I ran into this accidentally) before trying to connect()
Notice the code stuck forever with no timeout and no exception thrown
Environment
OS type and version: Ubuntu 20.04.4 LTS
Python version: 3.12.2
Cloud SQL Python Connector version: 1.13.0 to 1.18.0
Additional Details
I think it's reasonable to expect the connector would throw an exception or eventually timeout?
I've also tried setting timeout in the connector, tried setting timeout as part of the connect_args under create_engine same result.
changed the title [-]No exception thrown only a freeze when using a connection that is closed[/-][+]No exception thrown only code stuck forever when using a connection that is closed[/+]on Apr 7, 2025
changed the title [-]No exception thrown only code stuck forever when using a connection that is closed[/-][+]No exception thrown and no timeout when using a connection that is closed[/+]on Apr 7, 2025
changed the title [-]No exception thrown and no timeout when using a connection that is closed[/-][+]No exception thrown and no timeout when using a Connector that is closed[/+]on Apr 7, 2025
I totally agree, we should definitely add a check to the top of our connector.connect_async code to see if the connector has been closed and if it has throw an error 👍
I totally agree, we should definitely add a check to the top of our connector.connect_async code to see if the connector has been closed and if it has throw an error 👍
Activity
[-]No exception thrown only a freeze when using a connection that is closed[/-][+]No exception thrown only code stuck forever when using a connection that is closed[/+][-]No exception thrown only code stuck forever when using a connection that is closed[/-][+]No exception thrown and no timeout when using a connection that is closed[/+][-]No exception thrown and no timeout when using a connection that is closed[/-][+]No exception thrown and no timeout when using a Connector that is closed[/+]jackwotherspoon commentedon Apr 7, 2025
Thanks for raising an issue @seeker25 😄
I totally agree, we should definitely add a check to the top of our
connector.connect_asynccode to see if the connector has been closed and if it has throw an error 👍cloud-sql-python-connector/google/cloud/sql/connector/connector.py
Line 252 in e7f1068
@kgala2 Do you mind picking this up in the coming sprint?
kgala2 commentedon Apr 7, 2025
Thanks for the check suggestion. I'll add this task to my sprint.
kgala2 commentedon Oct 28, 2025
PR - #1269 is work in progress