diff --git a/Userland/Libraries/LibIPC/Connection.cpp b/Userland/Libraries/LibIPC/Connection.cpp index e6e6393b13..6c0451788f 100644 --- a/Userland/Libraries/LibIPC/Connection.cpp +++ b/Userland/Libraries/LibIPC/Connection.cpp @@ -49,11 +49,20 @@ ErrorOr ConnectionBase::post_message(MessageBuffer buffer) #endif ReadonlyBytes bytes_to_write { buffer.data.span() }; + int writes_done = 0; + size_t initial_size = bytes_to_write.size(); while (!bytes_to_write.is_empty()) { auto maybe_nwritten = m_socket->write(bytes_to_write); + writes_done++; if (maybe_nwritten.is_error()) { auto error = maybe_nwritten.release_error(); if (error.is_errno()) { + // FIXME: This is a hacky way to at least not crash on large messages + // The limit of 100 writes is arbitrary, and there to prevent indefinite spinning on the EventLoop + if (error.code() == EAGAIN && writes_done < 100) { + sched_yield(); + continue; + } shutdown_with_error(error); switch (error.code()) { case EPIPE: @@ -70,6 +79,9 @@ ErrorOr ConnectionBase::post_message(MessageBuffer buffer) bytes_to_write = bytes_to_write.slice(maybe_nwritten.value()); } + if (writes_done > 1) { + dbgln("LibIPC::Connection FIXME Warning, needed {} writes needed to send message of size {}B, this is pretty bad, as it spins on the EventLoop", writes_done, initial_size); + } m_responsiveness_timer->start(); return {};