Open fenss opened 1 month ago
To mitigate issues with dead sessions in MySQL due to network settings, you can configure the SQLAlchemy connection pool with specific parameters. Here are some options you can use:
Here is how you can configure these options in your create_engine
call within the DatabaseService
class:
from sqlalchemy import create_engine
def _create_engine(self) -> "Engine":
"""Create the engine for the database."""
settings_service = get_settings_service()
if settings_service.settings.DATABASE_URL and settings_service.settings.DATABASE_URL.startswith("sqlite"):
connect_args = {"check_same_thread": False}
else:
connect_args = {}
return create_engine(
self.database_url,
connect_args=connect_args,
pool_recycle=3600, # Recycle connections after 1 hour
pool_pre_ping=True, # Enable pre-ping to test connections
pool_timeout=30, # Wait up to 30 seconds for a connection
max_overflow=-1
)
In this example:
pool_recycle=3600
ensures that connections are recycled every hour.pool_pre_ping=True
enables the pre-ping feature to test connections before they are used.pool_timeout=30
sets the timeout for getting a connection from the pool to 30 seconds.These settings should help mitigate issues with dead sessions in MySQL due to network settings.
You can find the relevant code in the service.py
file of the langflow
repository. Here is the link to the file for reference: src/backend/langflow/services/database/service.py.
To continue the conversation, mention @dosu.
Describe the bug I use MySQL as the storage by setting environment variables:
But I can not find any pool settings in the database service code, so dead session comes out sometime because the networks setting.
Can you offer some options to set the SQLAlchemy pool? Thanks.