Database Connection Leaks in API Routes and CLI Commands
Description: Three database connection leaks might cause "too many clients" errors. Sessions are created but never closed.
Affected files:
augur/api/routes/dei.py:112-dei_report()endpoint never closes sessionaugur/api/routes/dei.py:39-dei_track_repo()endpoint lacks exception handling for session cleanupaugur/application/cli/user.py:67-reset_password()command never closes session
Code locations:
Issue 1: augur/api/routes/dei.py:112-132
def dei_report(application: ClientApplication):
session = DatabaseSession(logger, engine=current_app.engine)
# ... operations ...
return send_file(report.resolve()) # Missing session.close()
Issue 2: augur/api/routes/dei.py:39-101
def dei_track_repo(application: ClientApplication):
session = DatabaseSession(logger, engine=current_app.engine) # No context manager
# ... 60+ lines of operations ...
session.close() # Line 99 - not reached if exception occurs
Issue 3: augur/application/cli/user.py:67-78
def reset_password(username, password):
session = Session()
# ... operations ...
session.commit()
return click.echo("Password updated") # Missing session.close()
Note: Initial scan performed using Claude Code to identify potential database leaks across the codebase. I've manually verified these by reviewing the actual code.
This seems very related to #3392
Yep. After noticing #3392, I asked Claude Code to scan the codebase for further database connection leaks (verified outputs myself though.) I can open a PR for this if you also think these are issues.