diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index d84b52fe6d4f88..379faa1254c949 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -400,11 +400,12 @@ def _recv(self, size, read=_read): buf = io.BytesIO() handle = self._handle remaining = size - is_pipe = False + is_pipe = is_socket = False if size > self._default_pipe_size > 0: mode = os.fstat(handle).st_mode is_pipe = stat.S_ISFIFO(mode) - limit = self._default_pipe_size if is_pipe else remaining + is_socket = stat.S_ISSOCK(mode) + limit = self._default_pipe_size if is_pipe or is_socket else remaining while remaining > 0: to_read = min(limit, remaining) chunk = read(handle, to_read) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-09-01-06-34-54.gh-issue-123557.oOYkd2.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-01-06-34-54.gh-issue-123557.oOYkd2.rst new file mode 100644 index 00000000000000..48f54c70a1068c --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-01-06-34-54.gh-issue-123557.oOYkd2.rst @@ -0,0 +1 @@ +This PR would fix the problem of overallocating memory when reading from Unix sockets, extending the merged PR regarding pipes.