Open berendsliedrecht opened 1 year ago
we cannot reuse the session when the container restarts
I think this is expected right, but that we would expect Askar / SQLx to automatically handle closed sessions / connections rather than us having to manually recreate all the connections to the database?
I think this is expected right, but that we would expect Askar / SQLx to automatically handle closed sessions / connections rather than us having to manually recreate all the connections to the database?
Yeah it is expected, but the weird part is is that it works with a local database when that is restarted. There is a slight issue there because the docker container is restarted with docker-compose restart
and the local db with brews services stop postgresql@15 && brew services start postgresql@15
which might have different shutdown procedures.
I think this is expected right, but that we would expect Askar / SQLx to automatically handle closed sessions / connections rather than us having to manually recreate all the connections to the database?
Yeah it is expected, but the weird part is is that it works with a local database when that is restarted. There is a slight issue there because the docker container is restarted with
docker-compose restart
and the local db withbrews services stop postgresql@15 && brew services start postgresql@15
which might have different shutdown procedures.
Could it have something to do with this issue? Not sure, but it also has some different behaviour depending on local vs remote: https://github.com/launchbadge/sqlx/issues/2698
Each session wraps a PoolConnection, which does not (to my knowledge) support reconnection. Sessions are expected to be held for a short time before releasing the connection back to the pool, as otherwise you would likely hit the maximum number of open connections. It's strange to me that it would work with a local DB, as it would still need to reestablish the (TLS) connection and recreate any prepared statements. I'm not sure I totally understand where you're seeing this problem, though.
The problem we're experiencing is with neon.tech which will drop connections / restart sometimes.
We are closing sessions immediately for tenants, but the root session for the main wallet is kept open indefinitely. It's on our roadmap to work better with sessions in AFJ, but currently it's not so easy to change this behaviour.
So would you suggestion be to fix this in AFJ by improving the session handling logic?
This may be resolved by the update to sqlx 0.7.3
It is an issue inside of
sqlx
, but I will also open it here to keep track of it.issue: https://github.com/launchbadge/sqlx/issues/2763
Short version of it is that when we use a Postgres database within a Docker container, we cannot reuse the session when the container restarts. This all works when it is a local database however.
Small snippet with askar to reproduce:
cargo.toml
src/main.rs