File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
google/cloud/sql/connector Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -401,7 +401,7 @@ async def connect_async(
401401 if driver in LOCAL_PROXY_DRIVERS :
402402 local_socket_path = kwargs .pop ("local_socket_path" , "/tmp/connector-socket" )
403403 host = local_socket_path
404- start_local_proxy (
404+ self . _proxy = start_local_proxy (
405405 sock ,
406406 socket_path = f"{ local_socket_path } /.s.PGSQL.{ SERVER_PROXY_PORT } " ,
407407 loop = self ._loop
@@ -486,6 +486,13 @@ async def close_async(self) -> None:
486486 await asyncio .gather (* [cache .close () for cache in self ._cache .values ()])
487487 if self ._client :
488488 await self ._client .close ()
489+ if self ._proxy :
490+ proxy_task = asyncio .gather (self ._proxy )
491+ try :
492+ await asyncio .wait_for (proxy_task , timeout = 0.1 )
493+ except TimeoutError :
494+ pass # This task runs forever so it is expected to throw this exception
495+
489496
490497
491498async def create_async_connector (
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def start_local_proxy(
3030 ssl_sock : ssl .SSLSocket ,
3131 socket_path : Optional [str ] = "/tmp/connector-socket" ,
3232 loop : Optional [asyncio .AbstractEventLoop ] = None ,
33- ):
33+ ) -> asyncio . Task :
3434 """Helper function to start a UNIX based local proxy for
3535 transport messages through the SSL Socket.
3636
@@ -40,6 +40,9 @@ def start_local_proxy(
4040 socket_path: A system path that is going to be used to store the socket.
4141 loop (asyncio.AbstractEventLoop): Event loop to run asyncio tasks.
4242
43+ Returns:
44+ asyncio.Task: The asyncio task containing the proxy server process.
45+
4346 Raises:
4447 LocalProxyStartupError: Local UNIX socket based proxy was not able to
4548 get started.
@@ -66,7 +69,7 @@ def start_local_proxy(
6669 'Local UNIX socket based proxy was not able to get started.'
6770 )
6871
69- loop .create_task (local_communication (unix_socket , ssl_sock , socket_path , loop ))
72+ return loop .create_task (local_communication (unix_socket , ssl_sock , socket_path , loop ))
7073
7174
7275async def local_communication (
You can’t perform that action at this time.
0 commit comments