fix: restore finally block in handle_db_errors to prevent connection leaks (#38)
Reviewer correctly identified that removing the finally block introduced real connection leaks for handlers that do not call db.close() on their own error paths. Peewee's PooledDatabase.close() is a no-op on the second call, so double-close is harmless — the finally block provides necessary safety net. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7734e558a9
commit
55bf035db0
@ -800,6 +800,14 @@ def handle_db_errors(func):
|
||||
logger.info(f"Database rollback successful for {func_name}")
|
||||
except Exception as rollback_error:
|
||||
logger.error(f"Rollback failed in {func_name}: {rollback_error}")
|
||||
finally:
|
||||
try:
|
||||
db.close()
|
||||
logger.info(f"Database connection closed for {func_name}")
|
||||
except Exception as close_error:
|
||||
logger.error(
|
||||
f"Error closing database connection in {func_name}: {close_error}"
|
||||
)
|
||||
|
||||
raise HTTPException(
|
||||
status_code=500, detail=f"Database error in {func_name}: {str(e)}"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user