long2ice / asynch

An asyncio ClickHouse Python Driver with native (TCP) interface support.
https://github.com/long2ice/asynch
Apache License 2.0
185 stars 43 forks source link

The cursor closes the connection incorrectly #39

Closed poofeg closed 2 years ago

poofeg commented 2 years ago

The cursor closes the connection incorrectly. I'm not sure it should do it at all.

Code example:

logging.basicConfig(level=logging.DEBUG)
pool = await asynch.create_pool(maxsize=1)

async with pool.acquire() as conn:
    assert conn._is_closed is False  # <- ok
    async with conn.cursor() as cursor:
        await cursor.execute("SELECT 1")
    assert conn._is_closed is True  # <- not ok

async with pool.acquire() as conn:
    assert conn._is_closed is True  # <- not ok
    async with conn.cursor() as cursor:
        await cursor.execute("SELECT 1")    # <- but it works

You can see two stages of connection in the log:

DEBUG:asynch.proto.connection:Connecting. Database: default. User: default
DEBUG:asynch.proto.connection:Connecting to 127.0.0.1:9000
DEBUG:asynch.proto.connection:Connected to ClickHouse server version 22.1.3, revision: 54455
DEBUG:asynch.proto.connection:Query: SELECT 1
DEBUG:asynch.proto.connection:Connecting. Database: default. User: default
DEBUG:asynch.proto.connection:Connecting to 127.0.0.1:9000
DEBUG:asynch.proto.connection:Connected to ClickHouse server version 22.1.3, revision: 54455
DEBUG:asynch.proto.connection:Query: SELECT 1