8 views
-/https://github.com/berriai/litellm/issues/26619
GitHub ยท issue

#26619 [Bug]: Gunicorn worker recycling via --max_requests_before_restart leaks Postgres connections โ€” no keepalive configured, orphaned connections held for ~2 hours by Cloud SQL

  • State: open
  • Author: @manoj0116
  • Labels: stale

### Check for existing issues

- [x] I have searched the existing issues and checked that my issue is not a duplicate.

### What happened?

When running LiteLLM with `--run_gunicorn`, `--num_workers > 1`, and `--max_requests_before_restart`, Postgres connections accumulate on the database side and are never released until the OS TCP keepalive timeout (~2 hours on Cloud SQL / standard Linux). The pod itself never restarts โ€” the leak is entirely driven by Gunicorn worker recycling inside live pods.

### Root cause (confirmed by source)

**1. `proxy_shutdown_event()` is called with no try/except in the lifespan shutdown** (`proxy_server.py:1005`):

\`\`\`python # proxy_server.py ~line 1005 await proxy_shutdown_event() # no try/except โ€” exception aborts lifespan shutdown \`\`\`

**2. `PrismaClient.disconnect()` re-raises on failure** (`utils.py:3799`):

\`\`\`python async def disconnect(self): try: await self.db.disconnect() except Exception as e: # logs, then: raise e # propagates up through proxy_shutdown_event โ†’ lifespan โ†’ unhandled \`\`\`

**3. If `disconnect()` raises, the lifespan context manager exits with an exception.** Uvicorn catches this โ€ฆ

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 ยท 31d18h16m6s ago โ€” entered ยท #import:https:::github.com:berriai:litellm post #2680
The left issue requires diagnosing and safely changing asynchronous shutdown behavior across worker lifecycle boundaries, with database-driver error handling, concurrency, regression testing, and deployment-specific validation. The right issue is primarily a contained metadata update with straightforward schema and verification work.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search