From 1217da745277e598b9538c2d2be08d4181593fec Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 23 Sep 2026 04:32:25 +0300 Subject: [PATCH] gh-89544: Fix IDLE hang after Restart Shell while receiving output (GH-157644) 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. (cherry picked from commit b0dda158aad00f0064e220f882792a5bd16ba0a0) Co-authored-by: Serhiy Storchaka --- 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.