sqlalchemy-rqlite
sqlalchemy-rqlite copied to clipboard
After rqlite server restart, sqlalchemy-rqlite can not reconnect to server
My python code
engine = create_engine('rqlite+pyrqlite://localhost:4001/')
At the beginning, it can work properly. When I restart rqlited, the engine becomes unavailable.Until I run create_engine again, it work properly. Is this a issue?
It sounds like we need to give pyrqlite the ability to reconnect automatically. Do you know if some kind of exception is raised when it stops working? An exception would be a useful way to know when re-connection is necessary.
Sorry I can't catch the exception when rqlited restart. When I log str(e), it show '' only, I don't know why.I circumvent this problem by unusing connection pool engine = create_engine('rqlite+pyrqlite://localhost:4001/', poolclass=NullPool)
I've tested using the pyrqlite api directly, and I see multiple failure modes that vary depending on the python version.
For Python 2.7.12, I observed httplib.CannotSendRequest from HTTPConnection.request(), and httplib.BadStatusLine from HTTPConnection.getresponse().
For Python 3.6.1, I observed BrokenPipeError from HTTPConnection.request(), http.client.CannotSendRequest from HTTPConnection.request(), and http.client.RemoteDisconnected from HTTPConnection.getresponse().
https://github.com/rqlite/pyrqlite/commit/e0395b3ffc3bd6820aecdbffdeae61a47e581a0f fixes pyrqlite to re-open the connection in case of server restart.
We may want to add a pyrqlite connection parameter to control timeout.
Also, it would be better if pyrqilte raised an exception derived from its base Error class, and used exception chaining to indicate the underlying cause.