DPY-4011: the database or network closed connection in FastAPI

Exception during reset or similar
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\site-packages\sqlalchemy\pool\base.py", line 986, in _finalize_fairy
    fairy._reset(
  File "C:\Program Files\Python39\lib\site-packages\sqlalchemy\pool\base.py", line 1432, in _reset
    pool._dialect.do_rollback(self)
  File "C:\Program Files\Python39\lib\site-packages\sqlalchemy\engine\default.py", line 698, in do_rollback
    dbapi_connection.rollback()
  File "C:\Program Files\Python39\lib\site-packages\oracledb\connection.py", line 826, in rollback
    self._impl.rollback()
  File "src\\oracledb\\impl/thick/connection.pyx", line 735, in oracledb.thick_impl.ThickConnImpl.rollback
  File "src\\oracledb\\impl/thick/utils.pyx", line 456, in oracledb.thick_impl._raise_from_odpi
  File "src\\oracledb\\impl/thick/utils.pyx", line 446, in oracledb.thick_impl._raise_from_info
oracledb.exceptions.DatabaseError: DPY-4011: the database or network closed the connection
DPI-1080: connection was closed by ORA-03113
ORA-03113: end-of-file on communication channel
Process ID: 2429127
Session ID: 11672 Serial number: 46066
Help:
https://docs.oracle.com/error-help/db/ora-03113/A==))
def get_connection_to_oracle_db():
        
    engine = create_engine(
    f'oracle+oracledb://{O_USER}:{O_PASSWORD}@{O_HOST}:{O_PORT}/?service_name={O_DB}',
    pool_size=10,              
    max_overflow=20,            
    pool_timeout=60,           
    pool_recycle=300,
    thick_mode=thick_mode,    
    pool_pre_ping=True          
    )
    return engine
    
    
oracle_engine = get_connection_to_oracle_db()
Session = sessionmaker(bind=oracle_engine)

I use sqlalchemy to establish oracle connection to get data from oracle database in a FastAPI application.I established the connection in thick mode. Most of the Time my connection is perfect and I get data perfectly without any error.Sometimes I get the above mentioned error and this makes my API to freeze completely which doesnt allow to use other services.

Can anyone help me with this.