Handle telnet client socket resets gracefully#2076
Draft
liyimil wants to merge 1 commit into
Draft
Conversation
liyimil
force-pushed
the
agent/handle-telnet-rst
branch
from
July 18, 2026 01:56
b74cf0c to
0dea328
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
TelnetConnectionmethodOSErrorfromrecv()as a client disconnect and close the connectionWhy
A client that closes its socket with TCP RST makes
recv()raise from the event-loop reader callback. Because that callback had no exception boundary, asyncio reported an unhandled exception instead of cleaning up the telnet connection.Impact
Normal reads and graceful EOF handling are unchanged. Socket read errors now remove the reader and close the connection through the existing cleanup path.
Fixes #2073.
Checks
python -m pytest tests/test_telnet.py -q— 3 passedpython -m pytest tests -q -k "not test_emacs_history_bindings and not test_emacs_reverse_search and not test_prompt_session_memory_leak and not test_print_container"— 150 passed, 5 skipped, 4 deselectedruff check .— passedruff format --check .— passedmypy --strict src/prompt_toolkit/contrib/telnet/server.py --platform {win32,linux,darwin}— passedThe four locally deselected tests require arrow-key input or a Win32 console screen buffer, which are unavailable in the non-interactive Windows validation host.
Upstream CI ran the unit suite successfully on all six Python targets (3.10–3.14t), including formatting and typo checks on 3.14. Each job then hit the same unrelated full-repository Mypy errors in
application.py:1117,application.py:1121, andapplication.py:1124; the changed telnet module passes strict Mypy on all configured platforms.