Skip to content
Closed
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
5 changes: 4 additions & 1 deletion Lib/logging/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,10 @@ def handle(self):
slen = struct.unpack(">L", chunk)[0]
chunk = self.connection.recv(slen)
while len(chunk) < slen:
chunk = chunk + conn.recv(slen - len(chunk))
data = conn.recv(slen - len(chunk))
if not data:
return
chunk = chunk + data
if self.server.verify is not None:
chunk = self.server.verify(chunk)
if chunk is not None: # verified, can process
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3839,6 +3839,16 @@ def verify_reverse(stuff):
('ERROR', '2'),
], pat=r"^[\w.]+ -> (\w+): (\d+)$")

def test_listen_disconnect(self):
listener = logging.config.listen(0)
handler = listener.hdlr.__new__(listener.hdlr)
handler.connection = Mock(recv=Mock(side_effect=(
struct.pack('>L', 100), b'abc', b'')))

handler.handle()

self.assertEqual(handler.connection.recv.call_count, 3)

@support.requires_working_socket()
def test_listen_server_error(self):
# The "ready" event should be set even if the server fails to start.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an infinite loop in :func:`logging.config.listen` when a client
disconnects before sending the complete configuration payload.
Loading