LibIPC: Do not try to send a response back if transport was closed

The local handling of some messages might cause the transport to get
closed. If that's the case, we shouldn't try to send back a response.

This fixes many of the "Trying to post_message during IPC shutdown"
errors I was seeing when terminating Ladybird or when abnormally exiting
from LibWeb tests.
This commit is contained in:
Jelle Raaijmakers 2025-08-18 00:46:00 +02:00 committed by Tim Flynn
commit 63119355e3
Notes: github-actions[bot] 2025-08-18 00:53:17 +00:00

View file

@ -71,20 +71,23 @@ void ConnectionBase::handle_messages()
{ {
auto messages = move(m_unprocessed_messages); auto messages = move(m_unprocessed_messages);
for (auto& message : messages) { for (auto& message : messages) {
if (message->endpoint_magic() == m_local_endpoint_magic) { if (message->endpoint_magic() != m_local_endpoint_magic)
continue;
auto handler_result = m_local_stub.handle(move(message)); auto handler_result = m_local_stub.handle(move(message));
if (handler_result.is_error()) { if (handler_result.is_error()) {
dbgln("IPC::ConnectionBase::handle_messages: {}", handler_result.error()); dbgln("IPC::ConnectionBase::handle_messages: {}", handler_result.error());
continue; continue;
} }
if (!is_open())
continue;
if (auto response = handler_result.release_value()) { if (auto response = handler_result.release_value()) {
if (auto post_result = post_message(*response); post_result.is_error()) { if (auto post_result = post_message(*response); post_result.is_error())
dbgln("IPC::ConnectionBase::handle_messages: {}", post_result.error()); dbgln("IPC::ConnectionBase::handle_messages: {}", post_result.error());
} }
} }
}
}
} }
void ConnectionBase::wait_for_transport_to_become_readable() void ConnectionBase::wait_for_transport_to_become_readable()