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
Environment:
I’m hitting a repeated
OSError: [Errno 9] Bad file descriptorwhen debugging a Python FastAPI API in VS Code. The traces show failures inpydevd_comm.pyonsendall, followed by errors inclose(), plusprocess being replaced timed-outmessages. As I understand it,debugpy(the VS Code Python debug adapter) usespydevdas 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:
--reloadflag from theuvicornargs inlaunch.json, so it runs without automatic reload while debugging.debugpyfrom 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 7000The issue still reproduces.
"subProcess": falseinlaunch.jsonmakes the program finish cleanly, but no breakpoints hit, effectively behaving like a non-debug run.Error trace: