mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-02 16:45:08 +08:00
fix: Add proper error handling for database reconnection attempts (#12650)
## Problem When database connection is lost, the reconnection logic had a bug: if the first reconnect attempt failed, the second attempt was not wrapped in error handling, causing unhandled exceptions. ## Solution Added proper try-except blocks around the second reconnect attempt in both MySQL and PostgreSQL database classes to ensure errors are properly logged and handled. ## Changes - Fixed `_handle_connection_loss()` in `RetryingPooledMySQLDatabase` - Fixed `_handle_connection_loss()` in `RetryingPooledPostgresqlDatabase` Fixes #12294 --- Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=158349177 Co-authored-by: SID <158349177+0xsid0703@users.noreply.github.com>
This commit is contained in:
@ -281,7 +281,11 @@ class RetryingPooledMySQLDatabase(PooledMySQLDatabase):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed to reconnect: {e}")
|
logging.error(f"Failed to reconnect: {e}")
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
self.connect()
|
try:
|
||||||
|
self.connect()
|
||||||
|
except Exception as e2:
|
||||||
|
logging.error(f"Failed to reconnect on second attempt: {e2}")
|
||||||
|
raise
|
||||||
|
|
||||||
def begin(self):
|
def begin(self):
|
||||||
for attempt in range(self.max_retries + 1):
|
for attempt in range(self.max_retries + 1):
|
||||||
@ -352,7 +356,11 @@ class RetryingPooledPostgresqlDatabase(PooledPostgresqlDatabase):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed to reconnect to PostgreSQL: {e}")
|
logging.error(f"Failed to reconnect to PostgreSQL: {e}")
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
self.connect()
|
try:
|
||||||
|
self.connect()
|
||||||
|
except Exception as e2:
|
||||||
|
logging.error(f"Failed to reconnect to PostgreSQL on second attempt: {e2}")
|
||||||
|
raise
|
||||||
|
|
||||||
def begin(self):
|
def begin(self):
|
||||||
for attempt in range(self.max_retries + 1):
|
for attempt in range(self.max_retries + 1):
|
||||||
|
|||||||
Reference in New Issue
Block a user