microsoft / microsoft/vscode-python-debugger

VS Code + debugpy + FastAPI: debugpy socket closed (Bad file descriptor)

未關閉
#809 1 則留言 3 個 reaction 已指派 1 人 在 GitHub 檢視

@eleanorjboyd 已經在處理了。

開始於 2025年9月16日。

triage-needed
主要語言
TypeScript
星號
181
分支
126
平均合併
2 天 3 小時
30 天內合併 PR
3

描述

Environment:

  • OS: Microsoft Windows 11 Pro (10.0.22631)
  • WSL: Ubuntu 24.04.2 LTS, WSL 2.4.13.0, kernel 5.15.167.4-1
  • Execution: VS Code Remote-WSL (not SSH)
  • VS Code extension versions:
    • Python (ms-python.debugpy): 2025.14.0
    • Debugger (ms-python.debugpy): 2025.10.0

I’m hitting a repeated OSError: [Errno 9] Bad file descriptor when debugging a Python FastAPI API in VS Code. The traces show failures in pydevd_comm.py on sendall, followed by errors in close(), plus process being replaced timed-out messages. As I understand it, debugpy (the VS Code Python debug adapter) uses pydevd as its engine and they talk to the client over a TCP socket. This socket is getting closed while one thread is still sending data, and during teardown, another thread closes it again, hence the repeated stack traces. I've read that this usually happens due to server autoreload, multiprocessing without subProcess enabled, or Remote-SSH drops.

I have tried:

  • I have confirmed that the debugger is the cause, since when the application is running from the terminal (without the debugger) and a task is completed, no error occurs.
  • I removed the --reload flag from the uvicorn args in launch.json, so it runs without automatic reload while debugging.
  • Launched under debugpy from the terminal and attached from VS Code:
    python -m debugpy --listen 127.0.0.1:5678 --wait-for-client -m uvicorn main:app --host 0.0.0.0 --port 7000
    The issue still reproduces.
  • I tried updating the Python debugger extension, uninstalling and reinstalling, but VS Code reports it’s already the latest.
  • Setting "subProcess": false in launch.json makes the program finish cleanly, but no breakpoints hit, effectively behaving like a non-debug run.

Error trace:

Traceback (most recent call last):
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 422, in _on_run
cmd.send(self.sock)
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_net_command.py", line 111, in send
sock.sendall(("Content-Length: %s\r\n\r\n" % len(as_bytes)).encode("ascii"))
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_daemon_thread.py", line 53, in run
self._on_run()
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 432, in _on_run
self.py_db.dispose_and_kill_all_pydevd_threads()
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 2558, in dispose_and_kill_all_pydevd_threads
self._client_socket.close()
File "/home/daniel/.pyenv/versions/3.10.17/lib/python3.10/socket.py", line 502, in close
self._real_close()
File "/home/daniel/.pyenv/versions/3.10.17/lib/python3.10/socket.py", line 496, in _real_close
_ss.close(self)
OSError: [Errno 9] Bad file descriptor
Traceback (most recent call last):
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 422, in _on_run
cmd.send(self.sock)
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_net_command.py", line 111, in send
sock.sendall(("Content-Length: %s\r\n\r\n" % len(as_bytes)).encode("ascii"))
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_daemon_thread.py", line 53, in run
self._on_run()
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 432, in _on_run
self.py_db.dispose_and_kill_all_pydevd_threads()
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 2558, in dispose_and_kill_all_pydevd_threads
self._client_socket.close()
File "/home/daniel/.pyenv/versions/3.10.17/lib/python3.10/socket.py", line 502, in close
self._real_close()
File "/home/daniel/.pyenv/versions/3.10.17/lib/python3.10/socket.py", line 496, in _real_close
_ss.close(self)
OSError: [Errno 9] Bad file descriptor
Traceback (most recent call last):
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 422, in _on_run
cmd.send(self.sock)
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_net_command.py", line 111, in send
sock.sendall(("Content-Length: %s\r\n\r\n" % len(as_bytes)).encode("ascii"))
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_daemon_thread.py", line 53, in run
self._on_run()
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 432, in _on_run
self.py_db.dispose_and_kill_all_pydevd_threads()
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 2558, in dispose_and_kill_all_pydevd_threads
self._client_socket.close()
File "/home/daniel/.pyenv/versions/3.10.17/lib/python3.10/socket.py", line 502, in close
self._real_close()
File "/home/daniel/.pyenv/versions/3.10.17/lib/python3.10/socket.py", line 496, in _real_close
_ss.close(self)
OSError: [Errno 9] Bad file descriptor
Traceback (most recent call last):
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 422, in _on_run
cmd.send(self.sock)
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_net_command.py", line 111, in send
sock.sendall(("Content-Length: %s\r\n\r\n" % len(as_bytes)).encode("ascii"))
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_daemon_thread.py", line 53, in run
self._on_run()
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 432, in _on_run
self.py_db.dispose_and_kill_all_pydevd_threads()
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 2558, in dispose_and_kill_all_pydevd_threads
self._client_socket.close()
File "/home/daniel/.pyenv/versions/3.10.17/lib/python3.10/socket.py", line 502, in close
self._real_close()
File "/home/daniel/.pyenv/versions/3.10.17/lib/python3.10/socket.py", line 496, in _real_close
_ss.close(self)
OSError: [Errno 9] Bad file descriptor
Traceback (most recent call last):
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 422, in _on_run
cmd.send(self.sock)
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_net_command.py", line 111, in send
sock.sendall(("Content-Length: %s\r\n\r\n" % len(as_bytes)).encode("ascii"))
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_daemon_thread.py", line 53, in run
self._on_run()
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 432, in _on_run
self.py_db.dispose_and_kill_all_pydevd_threads()
File "/home/daniel/.vscode-server/extensions/ms-python.debugpy-2025.10.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 2558, in dispose_and_kill_all_pydevd_threads
self._client_socket.close()
File "/home/daniel/.pyenv/versions/3.10.17/lib/python3.10/socket.py", line 502, in close
self._real_close()
File "/home/daniel/.pyenv/versions/3.10.17/lib/python3.10/socket.py", line 496, in _real_close
_ss.close(self)
OSError: [Errno 9] Bad file descriptor
42.45s - pydevd: Sending message related to process being replaced timed-out after 5 seconds
43.14s - pydevd: Sending message related to process being replaced timed-out after 5 seconds
43.74s - pydevd: Sending message related to process being replaced timed-out after 5 seconds
44.34s - pydevd: Sending message related to process being replaced timed-out after 5 seconds
45.01s - pydevd: Sending message related to process being replaced timed-out after 5 seconds

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。