pydevd_comm.py start_client() does not set TCP_NODELAY on the connections it opens

Open Beginner friendly
#2,054 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python

Research direction

Start in 3rdparty/debugpy/DEBUGPY/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py at start_client(), and inspect how the socket is configured before the connection is opened. Confirm the connection used by debugpy --connect enables TCP_NODELAY and preserves the existing fallback behavior when the option is unavailable. Done means the source and an established connection reflect the expected setting.

Written by the indexing model from the issue text.

Description

Environment data

  • debugpy version: 1.8.20
  • OS and version: Linux and MacOS
  • 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 --git 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
index 64ac454f29..812bf59eb0 100644
--- 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 @@ def start_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 timeout
         timeout = int(os.environ.get("PYDEVD_CONNECT_TIMEOUT", 10))
%
Dominant language
Python
Stars
2.5k
Forks
202
Avg merge
5d 1h
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/debugpy

All issues in microsoft/debugpy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.