LibWeb: Crash less when the main thread exits while trying to render
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

Attach a 'job' to the main thread event loop, trusting that the event
loop implementation will cancel it when asked to quit. This is something
that our Unix implementation does, but isn't strictly part of the
contract of EventLoopImplementation.
This commit is contained in:
Andrew Kaster 2025-04-28 17:59:55 -06:00 committed by Andrew Kaster
parent 27db7ed11f
commit e5465ff8e5
Notes: github-actions[bot] 2025-04-29 15:52:25 +00:00
2 changed files with 12 additions and 0 deletions

View file

@ -13,7 +13,15 @@ namespace Web::HTML {
RenderingThread::RenderingThread()
: m_main_thread_event_loop(Core::EventLoop::current())
, m_main_thread_exit_promise(Core::Promise<NonnullRefPtr<Core::EventReceiver>>::construct())
{
// FIXME: Come up with a better "event loop exited" notification mechanism.
m_main_thread_exit_promise->on_rejection = [this](Error const&) -> void {
Threading::MutexLocker const locker { m_rendering_task_mutex };
m_exit = true;
m_rendering_task_ready_wake_condition.signal();
};
m_main_thread_event_loop.add_job(m_main_thread_exit_promise);
}
RenderingThread::~RenderingThread()
@ -58,6 +66,8 @@ void RenderingThread::rendering_thread_loop()
auto painting_surface = painting_surface_for_backing_store(task->backing_store);
m_skia_player->execute(*task->display_list, task->scroll_state_snapshot, painting_surface);
if (m_exit)
break;
m_main_thread_event_loop.deferred_invoke([callback = move(task->callback)] {
callback();
});