You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pydevd_comm.py start_client() does not set TCP_NODELAY on the connections it opens #2054
Python version (& distribution if applicable, e.g. Anaconda): 3.11 and later
Using VS Code or Visual Studio: No
Actual behavior
TCP_NODELAY is not set on the connections debugpy opens
Expected behavior
TCP_NODELAY is set on the connections debugpy opens
Steps to reproduce:
A connection established with debugpy --connect does not set TCP_NODELAY on the socket connection, which can cause latency when sending responses and events. This is can be verified simply by inspecting the pydevd_comm.py source code, or by using external tools to inspect the connection once it has been established.
We patched our copy of debugpy 1.8.20 as follows:
%diff--gita/3rdparty/debugpy/DEBUGPY/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.pyb/3rdparty/debugpy/DEBUGPY/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.pyindex64ac454f29..812bf59eb0100644---a/3rdparty/debugpy/DEBUGPY/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py+++b/3rdparty/debugpy/DEBUGPY/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py@@ -524,6+524,15 @@ defstart_client(host, port):except (AttributeError, OSError):pass# May not be available everywhere.+try:+# TVT-46072: "Missing TCP_NODELAY on debugpy's DAP tracer connection+# causes Nagle-induced latency in Python debugging". Disable Nagle's+# algorithm so small DAP messages are sent immediately instead of+# being buffered, reducing round-trip latency.+s.setsockopt(socket_module.IPPROTO_TCP, socket_module.TCP_NODELAY, 1)+except (AttributeError, OSError):
+pass# May not be available everywhere.+try:
# 10 seconds default timeouttimeout=int(os.environ.get("PYDEVD_CONNECT_TIMEOUT", 10))
%
Still reproduces on debugpy 1.8.21 (Python 3.13, Linux), with the adapter launched over stdio (python -m debugpy.adapter) and the debuggee connecting back over TCP. While the debuggee is stopped, the median round trip of a threads request is about 41 ms. With TCP_NODELAY set on pydevd's writer socket it is about 0.5 ms.
Every message pays the delay, not just some. NetCommand.send (_pydevd_bundle/pydevd_net_command.py:111-112) writes the Content-Length header and the JSON body as two separate sendall calls. Nagle's algorithm then holds the body until the header's delayed ACK arrives, about 40 ms on Linux.
#2066 sets the option on both the start_server and start_client sockets, and that matches the fix we validated. Sending the header and body in a single sendall would also avoid the delay for anyone still on a socket without the option.
Activity
nightcityblade commentedon Aug 16, 2026
Hi, I'd like to work on this. I'll submit a PR shortly.
drusmanbashir commentedon Nov 15, 2026
Still reproduces on debugpy 1.8.21 (Python 3.13, Linux), with the adapter launched over stdio (
python -m debugpy.adapter) and the debuggee connecting back over TCP. While the debuggee is stopped, the median round trip of athreadsrequest is about 41 ms. WithTCP_NODELAYset on pydevd's writer socket it is about 0.5 ms.Every message pays the delay, not just some.
NetCommand.send(_pydevd_bundle/pydevd_net_command.py:111-112) writes theContent-Lengthheader and the JSON body as two separatesendallcalls. Nagle's algorithm then holds the body until the header's delayed ACK arrives, about 40 ms on Linux.#2066 sets the option on both the
start_serverandstart_clientsockets, and that matches the fix we validated. Sending the header and body in a singlesendallwould also avoid the delay for anyone still on a socket without the option.