Skip to content

No exception thrown and no timeout when using a Connector that is closed #1268

@seeker25

Description

@seeker25

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?

  1. Close the connection intentionally (I ran into this accidentally) before trying to connect()
  2. Notice the code stuck forever with no timeout and no exception thrown

Environment

  1. OS type and version: Ubuntu 20.04.4 LTS
  2. Python version: 3.12.2
  3. 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.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions