Fix python_server.py infinite loop on EOF (fixes #25620) by anthonykim1 · Pull Request #25746 · microsoft/vscode-python

@anthonykim1

When VS Code closes, the STDIN stream closes and readline() returns
empty bytes (b''). Previously this was incorrectly treated as an
empty line separator, causing an infinite loop with 100% CPU usage.

This fix:
- Detects EOF in get_headers() by checking for b'' and raising EOFError
- Handles EOFError in all three places that call get_headers():
  - The main loop
  - handle_response()
  - custom_input()
- Exits gracefully with sys.exit(0) when EOF is detected

The key insight is distinguishing between:
- EOF: readline() returns b'' (empty bytes)
- Empty line: readline() returns b'\r\n' or b'\n' (newline bytes)

Also added comprehensive unit tests to verify the fix.

@anthonykim1 anthonykim1 added the bug

Issue identified by VS Code Team member as probable bug

label

Jan 22, 2026

DonJayamanne