From eb8914a194c1c2bb51e49d9e3ef564c7150d2c46 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 16 Sep 2026 23:25:32 +0300 Subject: [PATCH] gh-89544: Fix IDLE hang after Restart Shell while receiving output RPCClient.accept() reinitializes the SocketIO for the new connection, but the receive buffer kept the partially received packet from the old connection, so no message from the new user process was ever complete. --- Lib/idlelib/idle_test/test_rpc.py | 19 +++++++++++++++++++ Lib/idlelib/rpc.py | 9 +++++---- ...6-09-17-01-00-00.gh-issue-89544.rstbuf.rst | 2 ++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2026-09-17-01-00-00.gh-issue-89544.rstbuf.rst diff --git a/Lib/idlelib/idle_test/test_rpc.py b/Lib/idlelib/idle_test/test_rpc.py index 81eff398c72f45b..15c3ed14b8f6f3e 100644 --- a/Lib/idlelib/idle_test/test_rpc.py +++ b/Lib/idlelib/idle_test/test_rpc.py @@ -1,9 +1,28 @@ "Test rpc, coverage 20%." from idlelib import rpc +import socket +import struct import unittest +class SocketIOTest(unittest.TestCase): + + def test_reconnect_discards_partial_packet(self): + # gh-89544: RPCClient.accept() reinitializes the SocketIO after + # a restart; a partially received packet must not be kept. + old_sock, old_peer = socket.socketpair() + new_sock, new_peer = socket.socketpair() + with old_sock, old_peer, new_sock, new_peer: + sockio = rpc.SocketIO(old_sock) + old_peer.sendall(struct.pack(' reading count; 1 => reading data def close(self): sock = self.sock @@ -345,10 +350,6 @@ def putmessage(self, message): raise OSError("socket no longer exists") s = s[n:] - buff = b'' - bufneed = 4 - bufstate = 0 # meaning: 0 => reading count; 1 => reading data - def pollpacket(self, wait): self._stage0() if len(self.buff) < self.bufneed: diff --git a/Misc/NEWS.d/next/IDLE/2026-09-17-01-00-00.gh-issue-89544.rstbuf.rst b/Misc/NEWS.d/next/IDLE/2026-09-17-01-00-00.gh-issue-89544.rstbuf.rst new file mode 100644 index 000000000000000..4a4c885eff96818 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2026-09-17-01-00-00.gh-issue-89544.rstbuf.rst @@ -0,0 +1,2 @@ +Fix IDLE hanging after Restart Shell while receiving a large output from the +user process.