Proper handling of SQLAlchemy database sessions #520
Labels
impact: high 🟥
This issue affects most of the conda-store users or is a critical issue
type: bug 🐛
Something isn't working
I am convinced this is due to sqlalchemy sessions not being properly handled within conda-store server and workers. This also addresses issues seen in #459. There should be clear boundaries around sessions and they should never be passed between threads since they are not thread-safe https://docs.sqlalchemy.org/en/13/orm/session_basics.html#is-the-session-thread-safe.
Currently
main
is broken. This was shown clearly byconda-store/conda-store-server/conda_store_server/server/app.py
Line 190 in 5507732
conda_store_server.server.auth.Authentication
and the value is used across threads (each fastapi route call potentially runs on a separate thread).A simple fix is to pass the session_factory instead of session:
But this "fix" leads to additional errors about closing sessions in other places. See the following errors message.
All this is to say that we need to have a clearer boundaries on when a session begins/ends.
The major refactor here is that
conda_store_server.app.CondaStore
cannot handle the session instance and instead it needs to be passed along from the web request or celery task.The text was updated successfully, but these errors were encountered: