Skip to content

Connection to external DB gets dropped #192

@kmilo9999

Description

@kmilo9999

I deployed rag-api and have the database on an external server. I noticed that after a while (approx. 30 mins) the connection with the database is dropped and files uploaded through librechat generate an error. Chekcing the rag-api log I get:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly

        This probably means the server terminated abnormally

        before or while processing the request.


[SQL: SELECT langchain_pg_collection.name AS langchain_pg_collection_name, langchain_pg_collection.cmetadata AS langchain_pg_collection_cmetadata, langchain_pg_collection.uuid AS langchain_pg_collection_uuid 

FROM langchain_pg_collection 

WHERE langchain_pg_collection.name = %(name_1)s 

 LIMIT %(param_1)s]

(Background on this error at: https://sqlalche.me/e/20/e3q8)


The documentation in the link says :



OperationalError
Exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc.

This error is a [DBAPI Error](https://docs.sqlalchemy.org/en/20/errors.html#error-dbapi) and originates from the database driver (DBAPI), not SQLAlchemy itself.

The OperationalError is the most common (but not the only) error class used by drivers in the context of the database connection being dropped, or not being able to connect to the database. For tips on how to deal with this, see the section [Dealing with Disconnects](https://docs.sqlalchemy.org/en/20/core/pooling.html#pool-disconnects).

Looking at this forum, it can be solved by adding a parameter in the postgresql+psycopg2 connection. pool_pre_ping=True .
Taking a look at your config.py , there is no such a way to add this parameter.

Any thoughts on what can be done ?

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions