Skip to content

connector.connect() hangs on exit #26

@shivaal-scio

Description

@shivaal-scio

Repro:

python3 -m venv cloudsql_env
source cloudsql_env/bin/activate
pip install git+https://github.com/GoogleCloudPlatform/cloud-sql-python-connector@41e317ecdf6131d933ee455cd68fc4006aac8584

ipython
> from google.cloud.sql.connector import connector
> conn = connector.connect(instance_connection_string=<instance>, driver='pymysql', user=<user>, password=<password>, db=<db>)
> exit
[hangs]

This is hanging because the _loop.run_forever thread created on connector.py#L33 is still running in the background. I was able to fix this by setting it as a daemon thread, so that it gets killed when the program exits:

_thread = Thread(target=_loop.run_forever, daemon=True)

@crwilcox I believe this was Ryan's intern project, but I'd really appreciate if this could be fixed, even if this is no longer actively maintained. Would you mind making the change? I've confirmed that with them, I can make a connection using this library. (FWIW I believe the creator of the previous issue was not affected because Dataflow might kill the process on its own.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions