Closed jvhellemond closed 9 months ago
Hi @jvhellemond, one idea might be to use a connection pool, such as one from SQLAlchemy https://docs.sqlalchemy.org/en/14/core/pooling.html they can be used with DBAPI connections. I've used SQLAlchemy on long-running servers and haven't had any connection problems that I can remember. I think it's because each connection has a lifetime, and that lifetime is shorter than the time the server takes to close old connections. So maybe you could use that strategy of maximum idle times for your connection pool?
Hi,
In order to reuse a connection, I assign it to a variable an keep it around. Sometimes, when the connection has been open for a long time, the server understandibly closes it. I haven't found a stable way of detecting this. If I could, I could refresh the cached connection. Currently, if I try to use a closed connection, I have to wait for a timeout from the socket and eventually an exceptions.InterfaceError from pg8000:
which causes:
I tried checking
<connection>._usock._closed
, but that remains False. Any suggestion? I'd be happy to work on this or submit a PR. Please hmu if this issue is unclear. Thanks!