Skip to content

gh-160683: Stop half-closing the remote debugging interrupt socket - #160716

Open
summeriver13 wants to merge 1 commit into
python:mainfrom
summeriver13:fix/remote-pdb-idle
Open

summeriver13 wants to merge 1 commit into
python:mainfrom
summeriver13:fix/remote-pdb-idle

Conversation

@summeriver13

@summeriver13 summeriver13 commented Oct 26, 2026 •

Copy link
Copy Markdown

The interrupt channel is write-only. The client only calls sendall() on it
(Lib/pdb.py:3517), and the target only reads. Half-closing the target's write side
therefore sent a FIN that no one consumed, and Windows keeps a half-closed connection
in FIN_WAIT_2 for 120 seconds and then resets it. An idle debugging session silently
lost its interrupt channel.

Dropping the call leaves the connection in ESTABLISHED until one end closes it.
Nothing else changes: the listener still polls with a 0.25 s timeout, so it can exit
when the interpreter shuts down.

The half-close came in with the first version of the listener (5993e06, gh-132975).
Its author confirmed that it was only meant to document the one-way direction:
#160683 (comment)

The new test starts _PdbServer._start_signal_listener() in a subprocess and asserts
that the accepted socket never sees EOF. With the half-close put back, it fails in
147 ms, so it does not depend on the 120 s timer; with this change it passes.

I ran python.exe -m test test_remote_pdb test_pdb on Windows 11 (26100) with a
Release/MSVC build: 289 tests run, 17 skipped, all pass. This affects 3.14 and 3.15
as well; both branches have the same listener.

Fixes #160683

@summeriver13

Copy link
Copy Markdown
Author

All checks are green, including the Windows builds.

@gaogaotiantian, could you review this? It only touches Lib/pdb.py: the interrupt listener stops half-closing the socket. A half-closed connection waits in FIN_WAIT_2, and Windows resets it after 120 seconds, which drops the interrupt channel of an idle remote session (gh-160683). The author of that line confirmed that it only documented the one-way direction: #160683 (comment)

The new test starts the listener in a subprocess and asserts that the accepted socket never sees EOF. It fails in 147 ms without the change.

@cfbolz cfbolz left a comment

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.

looks good to me, apart from my one comment

Comment thread Lib/pdb.py Resolved
@bedevere-app

bedevere-app Bot commented Nov 2, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@summeriver13

Copy link
Copy Markdown
Author

I have made the requested changes; please review again.

@cfbolz I removed the comment block in Lib/pdb.py. The new test test_interrupt_socket_is_not_half_closed covers the behavior, so a comment is redundant.

Test results on a native Windows build (Python 3.16.0a1+dev):

  • ./PCbuild/amd64/python.exe -m test test_remote_pdb: 50 tests, OK (skipped=2).
  • ./PCbuild/amd64/python.exe -m test test_pdb: 239 tests, SUCCESS (skipped=15).

@bedevere-app

bedevere-app Bot commented Nov 2, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@cfbolz: please review the changes made to this pull request.

@bedevere-app
bedevere-app Bot requested a review from cfbolz November 2, 2026 10:42

@cfbolz cfbolz left a comment

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.

I am fine with this. @godlygeek would you have time to take a quick look too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: remote pdb loses its interrupt connection after about 120 seconds

2 participants