Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ProgrammingError on async race condition when using pool execute many #71

Open
solebox opened this issue Jul 10, 2023 · 6 comments
Open

Comments

@solebox
Copy link

solebox commented Jul 10, 2023

when using execute many to insert multiple entries into clickhouse with the following code to rapidly insert records:

while values_batch in value_batches:
    async with self._db_pool.acquire() as conn:
                    async with conn.cursor() as cursor:
                         await cursor.executemany(ch_query, values_batch)

we get the following exeption:
ProgrammingError("records have not fetched, fetch all before execute next")

probably also an issue with a single execute

@Wally110
Copy link

I encountered the same issue.

@lxneng
Copy link
Contributor

lxneng commented Oct 17, 2023

Same issue

@NekitPnt
Copy link

same

@itssimon
Copy link

itssimon commented Feb 29, 2024

I'm hitting this during ClickHouse server updates, when the connection gets dropped by the database. Always have to restart my application to recover from this.

Can confirm it happens with normal execute, not just executemany.

@pufit
Copy link
Contributor

pufit commented Mar 12, 2024

For the time being, while these changes haven't been released, you can check this snippet of code

pool: Pool | None = None


@contextlib.asynccontextmanager
async def with_clickhouse(**kwargs):
    global pool
    pool = await asynch.create_pool(**kwargs)

    try:
        yield pool
    finally:
        pool.close()
        await pool.wait_closed()
        pool = None


@contextlib.asynccontextmanager
async def session_scope() -> DictCursor:
    if pool is None:
        raise RuntimeError('out of `with_clickhouse()` scope')

    async with pool.acquire() as conn:
        try:
            async with conn.cursor() as cursor:
                yield cursor
        finally:
            if conn._connection.is_query_executing:
                await conn._connection.disconnect()

gnomeby added a commit to vizor-games/asynch that referenced this issue Mar 21, 2024
@gnomeby
Copy link
Contributor

gnomeby commented Mar 21, 2024

Fix for correct checking disconnected connections: #98

gnomeby added a commit to vizor-games/asynch that referenced this issue Mar 21, 2024
…eck_life_connection

long2ice#71 Correct check life connection
long2ice added a commit that referenced this issue Apr 22, 2024
…e_connection

#71 Correct check life connection
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants