From 8095663f869057a89a6268c2fc1ec13504e7b849 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 24 May 2025 01:20:35 -0600 Subject: [PATCH] LibIPC: Chunk sent file descriptors by MAX_TRANSFER_FDS This limitation of the underlying Unix socket implementation can cause IPC failures on pages with tons of images and network requests. Modify the code called from TransportSocket's send thread to limit the number of fds to MAX_TRANSFER_FDS, and ensure that we will keep sending as long as we have either bytes or file descriptors to send. --- Libraries/LibIPC/TransportSocket.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Libraries/LibIPC/TransportSocket.cpp b/Libraries/LibIPC/TransportSocket.cpp index ebf241ad453..0fb037c7cfd 100644 --- a/Libraries/LibIPC/TransportSocket.cpp +++ b/Libraries/LibIPC/TransportSocket.cpp @@ -46,7 +46,12 @@ SendQueue::BytesAndFds SendQueue::peek(size_t max_bytes) auto bytes_to_send = min(max_bytes, m_stream.used_buffer_size()); result.bytes.resize(bytes_to_send); m_stream.peek_some(result.bytes); - result.fds = m_fds; + + if (m_fds.size() > 0) { + auto fds_to_send = min(m_fds.size(), Core::LocalSocket::MAX_TRANSFER_FDS); + result.fds = Vector { m_fds.span().slice(0, fds_to_send) }; + // NOTE: This relies on a subsequent call to discard to actually remove the fds from m_fds + } return result; } @@ -287,7 +292,7 @@ TransportSocket::ShouldShutdown TransportSocket::read_as_many_messages_as_possib } auto bytes_read = maybe_bytes_read.release_value(); - if (bytes_read.is_empty()) { + if (bytes_read.is_empty() && received_fds.is_empty()) { should_shutdown = true; break; }