Skip to content

fix(tests): wait for every thread of a killed worker before treating it as gone - #47148

Merged
yuneng-berri merged 1 commit into
mainfrom
litellm_inspiring_lumiere_616622
Oct 17, 2026
Merged

yuneng-berri merged 1 commit into
mainfrom
litellm_inspiring_lumiere_616622

Conversation

@yuneng-berri

@yuneng-berri yuneng-berri commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • A zombie worker counts as gone only once its last thread exits
  • On macOS psutil can't read a zombie's threads, so the old check still applies there

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays 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 all

nodes="tests/integration/observability/test_grayswan_wire_chaos.py::test_worker_kill_mid_burst_survivor_keeps_serving tests/integration/observability/test_langfuse_delivery.py::test_audit_surviving_worker_keeps_serving_after_kill tests/integration/observability/test_guardrail_effects.py::test_disconnect_scans_keep_recording_after_a_worker_is_killed"
for i in $(seq 1 11); do for tree in /base /fix; do (cd $tree && python tests/integration/run.py extensions --workers 2 --results /repro/results/$(basename $tree)-$i $nodes > /repro/results/$(basename $tree)-$i.out 2>&1); done; done

Before (3c19b41)

  1. Ran the loop above on the tree without the fix
  2. 4 of 11 iterations were red and 5 of 33 test runs failed. Every failure was httpx.ReadError: [Errno 104] Connection reset by peer on the first request after the kill
base-2   1 failed, 2 passed   test_langfuse_delivery.py::test_audit_surviving_worker_keeps_serving_after_kill
base-3   2 failed, 1 passed   test_guardrail_effects.py::test_disconnect_scans_keep_recording_after_a_worker_is_killed
                              test_grayswan_wire_chaos.py::test_worker_kill_mid_burst_survivor_keeps_serving
base-4   1 failed, 2 passed   test_guardrail_effects.py::test_disconnect_scans_keep_recording_after_a_worker_is_killed
base-11  1 failed, 2 passed   test_guardrail_effects.py::test_disconnect_scans_keep_recording_after_a_worker_is_killed
other 7 iterations            3 passed

After (1f4b864)

  1. Ran the same loop, interleaved with the Before runs, on the tree with the fix
  2. 0 of 11 iterations were red, 0 of 33 test runs failed, and there were 0 connection resets
fix-1 .. fix-11   3 passed   resets=0

The new unit test fails on the unfixed line, and it also fails on the <= 2, < 1 and >= 1 mutants of the new check (Linux container)

Type

✅ Test

Caveats (if any)

Low

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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 peer when the harness treated a killed worker as finished too early.

_is_gone in the integration process helper no longer treats a process as gone on STATUS_ZOMBIE alone; it also requires num_threads() <= 1, so WorkerKill / _wait_until_gone keep 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_gone stays 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.

…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

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yuneng-berri

Copy link
Copy Markdown
Contributor Author

cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@yuneng-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

kerry-berri commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

litellm-stampbot: risk low

Approved at 1f4b864.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Cursor Bugbot: Low Risk at 1f4b864. Test-harness-only change to process teardown detection; no production proxy or runtime behavior is modified.
Bugbot Low is low, Medium and High are high. The judge model was not called.

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@kerry-berri kerry-berri added the risk:low Small, isolated, low-risk change label Oct 17, 2026

@kerry-berri kerry-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low risk by rule and by judgement at 1f4b864

@yuneng-berri
yuneng-berri merged commit 0431e75 into main Oct 17, 2026
142 of 144 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_inspiring_lumiere_616622 branch October 17, 2026 20:51
yuneng-berri added a commit that referenced this pull request Oct 17, 2026
…#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Small, isolated, low-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants