diff --git a/Userland/Libraries/LibIPC/Connection.cpp b/Userland/Libraries/LibIPC/Connection.cpp index fe69902221..30b54a5576 100644 --- a/Userland/Libraries/LibIPC/Connection.cpp +++ b/Userland/Libraries/LibIPC/Connection.cpp @@ -157,6 +157,15 @@ ErrorOr> ConnectionBase::read_as_much_as_possible_from_socket_without } u8 buffer[4096]; + + bool should_shut_down = false; + auto schedule_shutdown = [this, &should_shut_down]() { + should_shut_down = true; + m_deferred_invoker->schedule([strong_this = NonnullRefPtr(*this)] { + strong_this->shutdown(); + }); + }; + while (m_socket->is_open()) { auto maybe_bytes_read = m_socket->read_without_waiting({ buffer, 4096 }); if (maybe_bytes_read.is_error()) { @@ -165,6 +174,11 @@ ErrorOr> ConnectionBase::read_as_much_as_possible_from_socket_without break; } + if (error.is_syscall() && error.code() == ECONNRESET) { + schedule_shutdown(); + break; + } + dbgln("ConnectionBase::read_as_much_as_possible_from_socket_without_blocking: {}", error); warnln("ConnectionBase::read_as_much_as_possible_from_socket_without_blocking: {}", error); VERIFY_NOT_REACHED(); @@ -172,12 +186,8 @@ ErrorOr> ConnectionBase::read_as_much_as_possible_from_socket_without auto bytes_read = maybe_bytes_read.release_value(); if (bytes_read.is_empty()) { - m_deferred_invoker->schedule([strong_this = NonnullRefPtr(*this)] { - strong_this->shutdown(); - }); - if (!bytes.is_empty()) - break; - return Error::from_string_literal("IPC connection EOF"); + schedule_shutdown(); + break; } bytes.append(bytes_read.data(), bytes_read.size()); @@ -186,6 +196,8 @@ ErrorOr> ConnectionBase::read_as_much_as_possible_from_socket_without if (!bytes.is_empty()) { m_responsiveness_timer->stop(); did_become_responsive(); + } else if (should_shut_down) { + return Error::from_string_literal("IPC connection EOF"); } return bytes;