Skip to content

Proxy fails to start on Windows with AttributeError: module 'os' has no attribute 'WNOHANG'. - #23494

Merged
ishaan-jaff merged 1 commit into
mainfrom
litellm-windows-waitpid-wnohang
Mar 12, 2026
Merged

Proxy fails to start on Windows with AttributeError: module 'os' has no attribute 'WNOHANG'.#23494
ishaan-jaff merged 1 commit into
mainfrom
litellm-windows-waitpid-wnohang

Conversation

@shivamrawat1

Copy link
Copy Markdown
Contributor

Cause: PR #21899 added a Prisma engine watchdog that uses os.waitpid() and os.WNOHANG, which are Unix-only. On Windows these are missing and cause the crash.
Fix: Add sys.platform == "win32" checks so that on Windows _try_waitpid_watch returns False (falling back to os.kill polling) and _reap_all_zombies returns an empty set.

Relevant issues

Pre-Submission checklist

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

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🐛 Bug Fix
✅ Test

Changes

Guard os.waitpid and os.WNOHANG usage with sys.platform check.
These APIs are Unix-only; on Windows they cause AttributeError
and prevent proxy startup.

- _try_waitpid_watch: return False on Windows, fall back to
  os.kill polling
- _reap_all_zombies: return empty set on Windows (no zombies)

Add unit tests for Windows path.

Made-with: Cursor
@vercel

vercel Bot commented Mar 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Mar 12, 2026 10:51pm

Request Review

@greptile-apps

greptile-apps Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a Windows-specific startup crash introduced in PR #21899, where the Prisma engine watchdog called os.waitpid() and os.WNOHANG — both Unix-only APIs — causing an AttributeError on Windows. The fix adds sys.platform == "win32" early-return guards to _reap_all_zombies and _try_waitpid_watch, ensuring Windows falls through gracefully to the existing os.kill(pid, 0) polling fallback (which works cross-platform).

  • litellm/proxy/utils.py: adds import sys and two if sys.platform == "win32": return ... guards. The _try_pidfd_watch method was already safe (guarded by hasattr(os, "pidfd_open")), and the os.kill polling path (_poll_engine_proc) is cross-platform.
  • tests/litellm/proxy/test_prisma_engine_watchdog.py: adds test_try_waitpid_watch_returns_false_on_windows and test_reap_all_zombies_returns_empty_on_windows using patch("sys.platform", "win32") to exercise the new guards. All new tests are mocked and make no real network calls.
  • Minor note: existing Unix-specific tests such as test_try_waitpid_watch_returns_false_when_not_child do not patch sys.platform, so on an actual Windows CI runner they would return False via the new Windows guard instead of the ChildProcessError path — the assertions still pass, but the test exercises a different code path than intended.

Confidence Score: 5/5

  • This PR is safe to merge — it is a narrow, well-tested defensive fix for a Windows crash with no impact on existing Unix behaviour.
  • The change is minimal (two early-return guards + import sys), the logic is straightforward, and the fallback to os.kill polling on Windows was already implemented and tested. No existing Unix code paths are altered. Two new mock-only tests cover the new branches. No backwards-incompatible changes, no new database queries, and no provider-specific code introduced.
  • No files require special attention.

Important Files Changed

Filename Overview
litellm/proxy/utils.py Adds sys.platform == "win32" guards to _reap_all_zombies and _try_waitpid_watch to prevent AttributeError on Windows where os.waitpid/os.WNOHANG are unavailable. The fix is minimal and correct; _try_pidfd_watch already had a hasattr(os, "pidfd_open") guard. The fallback to os.kill polling remains fully functional on Windows.
tests/litellm/proxy/test_prisma_engine_watchdog.py Adds two new unit tests for the Windows early-return paths. Tests use patch("sys.platform", "win32") which correctly patches the global sys module. One subtle issue: existing Unix-only tests (e.g. test_try_waitpid_watch_returns_false_when_not_child) do not guard against running on Windows, where they would return False via the new Windows check rather than the ChildProcessError path — still passing, but for the wrong reason.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[_start_engine_watcher] --> B[_try_waitpid_watch]
    B -- "Windows: sys.platform == 'win32'" --> C[return False]
    B -- "Unix: call os.waitpid with WNOHANG" --> D{is child?}
    D -- No --> E[return False]
    D -- Yes --> F[Start waitpid thread]
    F --> G[return True]

    C --> H[_try_pidfd_watch]
    E --> H
    H -- "no hasattr os.pidfd_open" --> I[return False]
    H -- "Linux: pidfd_open succeeds" --> J[return True]

    I --> K[os.kill polling fallback\n_poll_engine_proc every 1s]

    subgraph "_reap_all_zombies"
        L{sys.platform == 'win32'?}
        L -- Yes --> M[return empty set]
        L -- No --> N[os.waitpid -1 WNOHANG loop]
    end
Loading

Last reviewed commit: 4e87fca

@ishaan-jaff
ishaan-jaff merged commit f5ffc59 into main Mar 12, 2026
15 of 37 checks passed
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…#23494)

Guard os.waitpid and os.WNOHANG usage with sys.platform check.
These APIs are Unix-only; on Windows they cause AttributeError
and prevent proxy startup.

- _try_waitpid_watch: return False on Windows, fall back to
  os.kill polling
- _reap_all_zombies: return empty set on Windows (no zombies)

Add unit tests for Windows path.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants