Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/debugpy/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def listen(address, settrace_kwargs, in_process_debug_adapter=False):
block_until_connected=False,
**settrace_kwargs
)
return
listen.called = True
return host, port

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue · Please address or respond

port is still the requested input value here, so listen(0, in_process_debug_adapter=True) now returns (host, 0) rather than the OS-assigned port. This does not meet the documented endpoint contract or the PR's stated port-0 motivation. Please obtain and return pydevd's bound port, or narrow the change and its description to explicitly document this limitation.

[verified]


import subprocess

Expand Down
18 changes: 18 additions & 0 deletions tests/debugpy/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest

import debugpy.server.api as _api


@pytest.fixture
def no_settrace(monkeypatch):
# Avoid actually starting pydevd; we only care about listen()'s return value.
monkeypatch.setattr(_api, "_settrace", lambda **kwargs: None)
monkeypatch.setattr(_api.listen, "called", False)


def test_listen_in_process_returns_endpoint(no_settrace):
# Regression test for #1656: listen(..., in_process_debug_adapter=True) used
# to return None, unlike the out-of-process path which returns (host, port).
endpoint = _api.listen(("127.0.0.1", 5678), in_process_debug_adapter=True)
assert endpoint == ("127.0.0.1", 5678)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning · Non-blocking recommendation

The fixed-port, no-op _settrace test only verifies that the input endpoint is echoed back; it cannot catch the port=0 contract gap. Add coverage that establishes whether the in-process path returns the resolved bound port for port 0.

[verified]

assert _api.listen.called is True