Repository navigation
fix(tests): wait for every thread of a killed worker before treating it as gone - #47148
Conversation
…it as gone WorkerKill returned once the victim's main thread was a zombie. On Linux the process keeps its sockets open until its last thread exits, so a pooled keep-alive connection to the killed worker still looked idle and the next request through it got ECONNRESET. A zombie now counts as gone only once num_threads() is at most 1. Where psutil cannot read threads of a zombie (macOS) it raises ZombieProcess, a NoSuchProcess, so the old behavior holds
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1f4b864. Configure here.
|
@litellm-stampbot |
litellm-stampbot: risk lowApproved at Rules (
Cursor Bugbot: Low Risk at Pushes do not re-run this check. Comment |
kerry-berri
left a comment
There was a problem hiding this comment.
Low risk by rule and by judgement at 1f4b864
…#47174) * test(integration): run the bedrock mantle prompt cache and output limit wire tests on their own proxy (#47152) * test(integration): run the bedrock mantle prompt cache and output limit wire tests on their own proxy These two files register deployments with their own model settings on the gateway. They now boot a module-scoped proxy on a scratch database, so their setup cannot affect other tests that share the worker's proxy * test(integration): seed the isolated gateway with the same router settings as the worker gateway (cherry picked from commit 603ba6f) * test(e2e): enable prometheus_system on the redis chaos proxy config (#47160) #46484 moved the litellm_redis_circuit_breaker_* metrics behind service_callback prometheus_system, so the chaos proxy, which only set callbacks prometheus, stopped exposing them and the breaker assertion read 0 (cherry picked from commit 519906e) * fix(tests): wait for every thread of a killed worker before treating it as gone (#47148) WorkerKill returned once the victim's main thread was a zombie. On Linux the process keeps its sockets open until its last thread exits, so a pooled keep-alive connection to the killed worker still looked idle and the next request through it got ECONNRESET. A zombie now counts as gone only once num_threads() is at most 1. Where psutil cannot read threads of a zombie (macOS) it raises ZombieProcess, a NoSuchProcess, so the old behavior holds (cherry picked from commit 0431e75) * test(caching): assert sync cache-hit logging without depending on thread order (#47093) Sync success callbacks run on a thread pool, so the miss and the two hits can reach the logger in any order. Compare counts instead of the list order. (cherry picked from commit 77c2ac1) * test(e2e): hold failing-request RSS to a loose ceiling over two measured batches (#47170) The 48 MB budget on the third batch kept failing on the x86 release gate with no leak behind it. Isolated rc/1.107.0 and v1.105.1 stacks both grew about 60 MB on the third batch with gc-tracked objects flat, and both levelled off to a couple of MB per batch after twenty batches. Measure batches 3-4 against a 200 MB per-worker ceiling instead, which a native leak of 400 KB per failed request still trips. The stored-request size check stays the deterministic catch for the v1.100.0 leak (cherry picked from commit e0514d9) * fix(router): read an application profile's base model from metadata on a cache hit (#47144) * fix(router): read an application profile's base model from metadata on a cache hit The 1h prompt-cache pin check read base_model only from the top level of litellm_params. On a response-cache hit the params it sees carry the base model only under metadata.model_info, so an application-profile ARN resolved to itself and the pin was written for 5 minutes while the wire carried a 1h TTL. Read it through get_base_model_from_metadata, which also checks metadata.model_info * test(router): pin top-level base_model precedence over metadata model_info (cherry picked from commit 1e3641a)
TLDR
Problem this solves:
[Errno 104] Connection reset by peerkill()returns before the killed worker's sockets are closedHow it solves it:
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
The bug lives in the test harness, so the proof runs the three affected tests through the integration runner and does not use curl. Linux only, because macOS doesn't keep a zombie leader's other threads alive, so it can't reproduce this. Setup is a python:3.12-slim container with 4 CPUs, its own Postgres 16 and Redis 7.2, and
tests/integration/run.py extensions --workers 2. Each iteration runs the unfixed tree and then the fixed tree back to back, 11 iterations in allBefore (3c19b41)
httpx.ReadError: [Errno 104] Connection reset by peeron the first request after the killAfter (1f4b864)
The new unit test fails on the unfixed line, and it also fails on the
<= 2,< 1and>= 1mutants of the new check (Linux container)Type
✅ Test
Caveats (if any)
Low
_is_goneFinal Attestation
Note
Low Risk
Test-harness-only change to process teardown detection; no production proxy or runtime behavior is modified.
Overview
Fixes flaky worker-kill integration tests that could hit
[Errno 104] Connection reset by peerwhen the harness treated a killed worker as finished too early._is_gonein the integration process helper no longer treats a process as gone onSTATUS_ZOMBIEalone; it also requiresnum_threads() <= 1, soWorkerKill/_wait_until_gonekeep waiting until the last thread exits and listening sockets are actually torn down (on Linux, a zombie thread-group leader can still have live threads holding sockets).Adds a Linux-only unit test that spawns a process whose main thread exits while another thread keeps a socket open, and asserts
_is_gonestays false until that thread finishes.Reviewed by Cursor Bugbot for commit 1f4b864. Bugbot is set up for automated code reviews on this repo. Configure here.