- 
                Notifications
    You must be signed in to change notification settings 
- Fork 83
Open
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Bug Description
No exception thrown and no timeout when using a Connector that is closed, code stays stuck waiting
Example code (or command)
import os
from google.cloud.sql.connector import Connector
from sqlalchemy import create_engine
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'service-account.json'
connector = Connector()
def get_iam_connection():
	"""Establish connection using IAM authentication."""
	return connector.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 used
connector.close()
# It gets stuck waiting on the line below
with engine.connect() as conn:
        # 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.
Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.