asynch icon indicating copy to clipboard operation
asynch copied to clipboard

Not recovering from interrupted database connection while query is executing

Open itssimon opened this issue 1 year ago • 9 comments

If the connection to the ClickHouse database is interrupted while a query is executing, asynch is unable to recover from it. Any subsequent queries fail with the following exception:

ProgrammingError: some records have not been fetched. fetch the remaining records before executing the next query

It looks like this is because the is_query_executing attribute on the Connection remains True if the end of stream packet was missed.

I'm not even sure how to work around this. I've had to restart my application to recover from this, which is far from ideal.

itssimon avatar Feb 29 '24 04:02 itssimon

This may also be related to https://github.com/long2ice/asynch/issues/71

itssimon avatar Feb 29 '24 04:02 itssimon

still got this issue with latest master version

tiejunhu avatar May 30 '24 07:05 tiejunhu

Got this error too. And think i get the point. When we was release the connection to the pool we need to call reset_state. Then connection will be passed to new consumer clean

boolka avatar Jun 01 '24 10:06 boolka

@tiejunhu you can use my hint right now.

...
try:
    await cursor.execute(...)
except (SocketTimeoutError, NetworkError, gaierror):
    await conn.close()

You must close connection mannually on some network errors

boolka avatar Jun 01 '24 10:06 boolka

@tiejunhu you can use my hint right now.

...
try:
    await cursor.execute(...)
except (SocketTimeoutError, NetworkError, gaierror):
    await conn.close()

You must close connection mannually on some network errors

Thank you. I used a similar solution: close the connection before returning it to the pool, then retry the request.

tiejunhu avatar Jun 03 '24 07:06 tiejunhu