fix(proxy): recover from prisma-query-engine zombie process - #21707
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Author
Contributor
Greptile SummaryAdds a background watchdog to
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/utils.py | Adds ~190 lines implementing a prisma-query-engine watchdog: PID detection (via Prisma internals + /proc scan), pidfd-based event-driven monitoring, /proc polling fallback, death handling with exponential-backoff reconnect. Clean implementation with proper resource cleanup and guards against duplicate watchers. |
| litellm/proxy/proxy_server.py | Minimal integration: starts the watchdog after DB health check on startup, stops it during proxy shutdown. Two-line change, well-placed in the lifecycle. |
| tests/litellm/proxy/test_prisma_engine_watchdog.py | New test file covering 8 key scenarios: process disappearance, zombie detection, successful reconnect + re-arm, missing DATABASE_URL, clean shutdown, transient failure retry, permanent failure graceful degradation, pidfd handler task scheduling. All mock-based, no real network calls. |
| tests/proxy_unit_tests/test_proxy_server.py | Adds _start_db_health_check_loop mock to existing Prisma client test fixture to accommodate the new startup call. |
| tests/proxy_unit_tests/test_proxy_utils.py | Adds _start_db_health_check_loop mock to existing health-check-disabled test to prevent test failure from the new startup integration. |
| tests/test_litellm/proxy/test_proxy_server.py | Adds _start_db_health_check_loop and _stop_db_health_check_loop stub methods to MockPrisma class for compatibility with the new lifecycle hooks. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Proxy Startup] --> B[_start_db_health_check_loop]
B --> C{Find engine PID}
C -->|Not found| D[Log warning, no watchdog]
C -->|Found| E{pidfd_open available?}
E -->|Yes| F[Register pidfd reader]
E -->|No| G[Start /proc polling task, 2s interval]
F -->|Engine exits| H[_on_pidfd_readable]
G -->|Process gone/zombie| H2[Detect death in poll loop]
H --> I[_cleanup_watcher]
H2 --> I
I --> J[_handle_engine_death]
J --> K[Acquire reconnect lock]
K --> L[_reap_zombies for engine PID]
L --> M{DATABASE_URL set?}
M -->|No| N[Log error, stop]
M -->|Yes| O[Reconnect with backoff, max 5 retries]
O -->|Success| P[_start_db_health_check_loop re-arm]
O -->|All retries failed| Q[Log critical, watchdog inactive]
R[Proxy Shutdown] --> S[_stop_db_health_check_loop]
S --> I2[_cleanup_watcher]
Last reviewed commit: 866c609
Contributor
Author
Contributor
Author
Contributor
Author
Contributor
Author
7 tasks
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…erriAI#21707)" This reverts commit 977ad01.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
Related to the
All connection attempts failedissues reported after upgrading to v1.81.x (related: #15536 #15585 #20427).Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🐛 Bug Fix
Changes
prisma-query-enginecan silently die after heavy queries (like/tag/liston large datasets hitting OOM), and when it does every request that touches the DB returnsAll connection attempts failedand 401 for anything that queries the db.This PR extends the connection self-heal watchdog from #21706 with engine-process death detection. At startup the engine PID is discovered and watched via
pidfd_open(Linux 5.3+, event-driven) or/proc/<pid>/statpolling every 2s as fallback. On death,_run_reconnect_cyclecallsrecreate_prisma_clientto spawn a fresh engine subprocess and re-arms the watcher. If the engine is alive or unknown the existing lightweightdisconnect → connect → SELECT 1path from #21706 is used instead.Unit tests cover engine liveness detection, process disappearance and zombie state triggering reconnect, pidfd event while lock is held, heavy vs lightweight reconnect branching, missing
DATABASE_URL, and watcher lifecycle.