Skip to content

Truly independent web browser

LibWebView: Keep a report's proof of work from outliving the event loop

Jelle Raaijmakersb6180f945c54
diff --git a/Libraries/LibWebView/ReportSubmission.cpp b/Libraries/LibWebView/ReportSubmission.cpp
index 65fad611094..a3778d8643c 100644
--- a/Libraries/LibWebView/ReportSubmission.cpp
+++ b/Libraries/LibWebView/ReportSubmission.cpp
@@ -283,13 +283,17 @@ void ReportSubmission::solve_proof(ByteString token, u64 expected_work)
(void)m_proof_thread->join();
// The server chooses the difficulty, so the search runs on its own thread, at the priority of work that the user
- // follows through a progress indicator.
- auto& main_thread_event_loop = Core::EventLoop::current();
+ // follows through a progress indicator. A submission on its way keeps itself alive, so quitting the browser does not
+ // wait for the search, whose result only goes to the main thread's event loop while that loop is still there.
m_proof_thread = Threading::Thread::construct("Report proof"sv,
- [weak_this = make_weak_ptr<ReportSubmission>(), &cancelled = m_proof_cancelled, &main_thread_event_loop,
- attempt = m_attempt, token = move(token), expected_work]() mutable -> intptr_t {
+ [weak_this = make_weak_ptr<ReportSubmission>(), &cancelled = m_proof_cancelled,
+ main_thread_event_loop = Core::EventLoop::current_weak(), attempt = m_attempt, token = move(token),
+ expected_work]() mutable -> intptr_t {
auto nonce = solve_challenge(token, expected_work, cancelled);
- main_thread_event_loop.deferred_invoke(
+ auto event_loop = main_thread_event_loop->take();
+ if (!event_loop)
+ return 0;
+ event_loop->deferred_invoke(
[weak_this = move(weak_this), attempt, token = move(token), nonce]() mutable {
auto self = weak_this.strong_ref();
if (!self || self->m_attempt != attempt || self->m_proof_cancelled.load())