Skip to content

[Python/Snowflake] Connection sometimes hanging #3730

@Niivii

Description

@Niivii

What happened?

Connection is sometimes hanging or not closing properly while querying data from Snowflake via Polars.
Everything is successful on Snowflake side.

On ADBC 1.7.0, Go driver 1.14.1 and Polars 1.32.3 this would trigger our timeout function wrappers but with
ADBC 1.9.0,Go driver 1.17.0 and Polars 1.35.2 this is just left hanging.

Stack Trace

File "/home/appuser/app/main.py", line 94, in job
    sql_connection.create_snowflake_connection(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        job_settings.db_snowflake) as snowflake_connection,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.13/site-packages/adbc_driver_manager/dbapi.py", line 249, in __exit__
    self.close()
    ~~~~~~~~~~^^
  File "/.venv/lib/python3.13/site-packages/adbc_driver_manager/dbapi.py", line 351, in close
    self._conn.close()
    ~~~~~~~~~~~~~~~~^^
  File "adbc_driver_manager/_lib.pyx", line 1138, in adbc_driver_manager._lib.AdbcConnection.close
  File "adbc_driver_manager/_lib.pyx", line 334, in adbc_driver_manager._lib._AdbcHandle._check_open_children
  File "adbc_driver_manager/_lib.pyx", line 336, in adbc_driver_manager._lib._AdbcHandle._check_open_children
RuntimeError: Cannot close AdbcConnection with open AdbcStatement

How can we reproduce the bug?

with (
    sql_connection.create_snowflake_connection(
        job_settings.db_snowflake) as snowflake_connection,
):
    try:
        snowflake_df = db.get_snowflake_current_data(
            snowflake_connection=snowflake_connection,
        )
    # ...

@func_set_timeout(timeout=360)
def get_snowflake_current_data(
        snowflake_connection: adbc_driver_snowflake.dbapi.Connection,
) -> pl.DataFrame:
    with Path.open(Path("./query_snowflake.sql")) as query_snowflake:
        stmt_snowflake = query_snowflake.read()
    snowflake_df = pl.read_database(query=stmt_snowflake, connection=snowflake_connection)

    return snowflake_df

Environment/Setup

latest versions of adbc, polars, pyarrow, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions