LibIPC+LibWeb: Flush MessagePort messages before closing

The spec isn't super clear on what disentagling a MessagePort means. But
we are required to send all pending messages before closing the port.

This is a bit tricky because the transport socket performs writes on a
background thread. From the main thread, where the disentanglement will
occur, we don't really know the state of the write thread. So what we do
here is stop the background thread then flush all remaining data from
the main thread.
This commit is contained in:
Timothy Flynn 2025-05-20 16:21:17 -04:00 committed by Tim Flynn
parent 8b3355ed0d
commit 36da270dbe
Notes: github-actions[bot] 2025-05-21 10:56:21 +00:00
3 changed files with 85 additions and 36 deletions

View file

@ -146,11 +146,15 @@ WebIDL::ExceptionOr<void> MessagePort::transfer_receiving_steps(HTML::TransferDa
void MessagePort::disentangle()
{
if (m_remote_port)
if (m_remote_port) {
m_remote_port->m_remote_port = nullptr;
m_remote_port = nullptr;
m_remote_port = nullptr;
}
m_transport.clear();
if (m_transport) {
m_transport->close_after_sending_all_pending_messages();
m_transport.clear();
}
m_worker_event_target = nullptr;
}