Skip to content

Lots of idle sessions with sqlalchemy+psycopg #3645

Closed Answered by aranvir
aranvir asked this question in Q&A
Discussion options

You must be logged in to vote

And that is exactly the issue - instead of fetching the session maker from the plugin I implicitly create a new engine per session maker. Instead, I should get the session maker like

async def retrieve_user_handler(session: dict[str, Any], connection: ASGIConnection) -> User:
    """Fetches the current user state from the database and returns it as User instance."""
    sessionmaker: Callable[[], AsyncSession] = connection.app.state.get("session_maker_class")
    db_session = sessionmaker()

With this, I don't even exhaust the base pool of connections.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aranvir
Comment options

Answer selected by aranvir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant