Skip to content

logging.config.listen() enters an infinite loop when a client disconnects early #162091

Closed as duplicate

Description

@lpyu001

Bug report

Bug description

logging.config.listen() can enter an infinite loop and consume 100% of one CPU core when a client disconnects before sending the declared payload length.

In ConfigStreamHandler.handle(), the receive loop does not handle EOF. When the client closes the connection, recv() returns b'', leaving the buffer length unchanged and causing the loop to run indefinitely.

reproducer

import logging.config
import socket
import struct
import time

t = logging.config.listen(0)
t.daemon = True
t.start()
t.ready.wait()

with socket.create_connection(("localhost", t.port)) as s:
    s.sendall(struct.pack(">L", 100) + b"abc")

time.sleep(0.5)
start = time.process_time()
time.sleep(2)
print("CPU time:", time.process_time() - start)

logging.config.stopListening()

Actual behavior

The request-handling thread enters an infinite loop, consuming approximately one CPU core.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions