Mysql connection reset by peer

Hi all, finally i got my HA privecyidea setup working with a mysql galera cluster master-master, but if i leave my admin user logged for some minutes, it will be locked and when i try to login again i got for the first time:

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2013, ‘Lost connection to MySQL server during query ([Errno 104] Connection reset by peer)’)
[SQL: SELECT config.Key AS config_Key, config.Value AS config_Value, config.Type AS config_Type, config.Description AS config_Description
FROM config
WHERE config.Key = %(Key_1)s
LIMIT %(param_1)s]
[parameters: {‘Key_1’: ‘timestamp’, ‘param_1’: 1}]
(Background on this error at: Error Messages — SQLAlchemy 1.3 Documentation)

and i can’t login, entering again the password it will let me enter in

Is there a way to fix it ?

I searched and it seems that the problem can be sqalchemy timeout, so a fix could be using a pool_pre_ping and a pool_recycle but i don’t know where to put these.

I tried to add it to the

SQLALCHEMY_DATABASE_URI

after the dbname but it didn’t work, i got Internal Server Error

thanks in advance
Claudio