-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reconnecting fails with ConnectionResetError #127
Comments
@nils-borrmann-tacto , hello. This example does not reproduce the problem you encountered, locally two runs went fine. Example: import asyncio
import logging
from time import sleep
from asynch import Pool
logging.basicConfig(
level=logging.DEBUG, format="Example %(asctime)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S"
)
# connection_string ='clickhouse://@p4c0wmo0db.germanywestcentral.azure.clickhouse.cloud:9440/production?secure=True'
async def init_pool() -> Pool:
pool = Pool(minsize=1, maxsize=2) # , dsn=connection_string)
await pool.startup()
return pool
async def execute(pool: Pool):
async with pool.connection() as conn:
async with conn.cursor() as cursor:
await cursor.execute("SELECT 1")
ret = await cursor.fetchone()
assert ret == (1,)
async def main():
pool = await init_pool()
await execute(pool)
sleep(5 * 60) # waiting for 5 minutes
await execute(pool)
await pool.shutdown()
if __name__ == "__main__":
asyncio.run(main()) Result (kkk): Could you try with example locally and then with the original connection string?
|
Hi @stankudrow thanks for the quick reply. In your run, it didn't print this line
So it didn't run into the crash, because the server didn't close the connection. It was able to re-use the existing connection just fine. The crash only happens when a previously opened connection cannot be reused because it was closed by the server. I am using clickhouse cloud, and this is likely a behaviour that is not replicated by a local installation of clickhouse. I will see if I can better reproduce the issue locally, maybe by killing the locally running clickhouse instance. |
Yep, such an example would be nice to have as a unit test, but I am not sure I can compose one today. |
I managed to reproduce this error locally: #129 |
I'm connecting to clickhouse using the asynch Pool. If I let the connection idle for a few minutes, apparently the server closes the connection on its end. Now, the next time I try to execute a query using an existing pool, asynch gets a
ConnectionResetError
duringping()
, this is still handled gracefully, however when reconnecting, asynch tries to close the already closed connection and crashes, again with aConnectionResetError
. (On a sidenote: Sometimes I get aBrokenPipeError
instead ofConnectionResetError
)I managed to fix this quick-and-dirty by wrapping
self.writer.close()
in a try-except. Another option could be to setconnection.connected = False
in the error handling insideping()
.Demo code:
And output:
The text was updated successfully, but these errors were encountered: