8 views
-/https://github.com/berriai/litellm/issues/34269
GitHub · issue

#34269 [Bug] global_spend_refresh() leaks a PrismaClient/DB connection on every call

  • State: open
  • Author: @yryzhan-vitech
  • Labels: llm translation

### Check for existing issues

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

### What happened?

The `POST /global/spend/refresh` endpoint (`global_spend_refresh()`) instantiates a dedicated `PrismaClient` for the `REFRESH MATERIALIZED VIEW` step, calls `.connect()` on it, runs the query, and then returns **without ever calling `.disconnect()`**. Every call to this endpoint leaks a Prisma engine + its DB connection. Repeated refreshes (the Admin UI Usage tab, or any polling/monitoring that hits this endpoint) steadily accumulate idle Postgres connections until the DB reaches `max_connections` and the whole proxy starts failing with connection errors.

**Expected:** the endpoint adds zero net DB connections after it returns, no matter how many times it is called — the dedicated client must always be released.

**Actual:** each successful call opens a new Prisma engine/connection that is never released; the `idle` count in `pg_stat_activity` grows by one per call and never decreases, until `FATAL: sorry, too many clients already`.

### Steps to Reproduce

Reproducible on a stock proxy + Postgres, no special infra:

1. Start Postgres with a l…

GitHub resolver

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

Refresh page
vote history (3 events)
#0 of 0 · 31d18h21m14s ago — entered · #import:https:::github.com:berriai:litellm post #2590
The right issue is harder because it requires investigating and adapting an external provider’s authentication and challenge behavior, with broader integration and regression-testing risk; the left is a localized resource-lifecycle correction with focused validation.
The right issue is harder because it requires tracing database-client lifecycle across success and failure paths, preserving async behavior, and adding reliable regression coverage; the left is a localized provider branch using existing dependencies and caching.
#0 of 0 · 31d18h6m56s ago — current · #import:https:::github.com:berriai:litellm post #2837
The left item is harder because it expands an API response contract, requires ORM relation-loading and serialization validation, and may need configurable behavior plus performance and compatibility testing. The right item is a narrowly scoped resource-lifecycle correction with focused regression coverage.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search