Skip to content

Commit 77d922b

Browse files
fix: error on connect_async() event loop mismatch
1 parent 5712e9e commit 77d922b

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

google/cloud/sql/connector/connector.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@ async def connect_async(
266266
DnsNameResolutionError: Could not resolve PSC IP address from DNS
267267
host name.
268268
"""
269+
# check if event loop is running in current thread
270+
if self._loop != asyncio.get_running_loop():
271+
raise ConnectorLoopError(
272+
"Running event loop does not match 'connector._loop'. "
273+
"Connector.connect_async() must be called from the event loop "
274+
"the Connector was initialized with. If you need to connect "
275+
"across event loops/threads please use a new Connector object."
276+
)
277+
269278
if self._keys is None:
270279
self._keys = asyncio.create_task(generate_keys())
271280
if self._client is None:

0 commit comments

Comments
 (0)