From f2f2b6ef18907a76461b54e110618e7840971fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wierci=C5=84ski?= Date: Fri, 17 Nov 2023 16:16:38 +0100 Subject: [PATCH] wasm: Proxy emscripten_fetch() to the main thread Calling emscripten_fetch() on worker thread which never yields control back to the browser, will leave the fetch request pending forever. This can be a problematic for example in QML Loader, which tries to load resource by network. Proxy this function call to the main thread, so it can be processed by the browser. Fixes: QTBUG-118225 Pick-to: 6.6 6.5 Change-Id: I969d73f6a66670c4135960e08d2eedc8d2a6e5c3 Reviewed-by: Lorn Potter --- src/corelib/kernel/qeventdispatcher_wasm_p.h | 2 +- src/network/access/qnetworkreplywasmimpl.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_wasm_p.h b/src/corelib/kernel/qeventdispatcher_wasm_p.h index 27cf4552e9..564bbffa47 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm_p.h +++ b/src/corelib/kernel/qeventdispatcher_wasm_p.h @@ -53,6 +53,7 @@ public: void interrupt() override; void wakeUp() override; + static void runOnMainThreadAsync(std::function fn); static void socketSelect(int timeout, int socket, bool waitForRead, bool waitForWrite, bool *selectForRead, bool *selectForWrite, bool *socketDisconnect); protected: @@ -90,7 +91,6 @@ private: static void run(std::function fn); static void runOnMainThread(std::function fn); static void runAsync(std::function fn); - static void runOnMainThreadAsync(std::function fn); static QEventDispatcherWasm *g_mainThreadEventDispatcher; diff --git a/src/network/access/qnetworkreplywasmimpl.cpp b/src/network/access/qnetworkreplywasmimpl.cpp index d8190434cc..f7380a10d9 100644 --- a/src/network/access/qnetworkreplywasmimpl.cpp +++ b/src/network/access/qnetworkreplywasmimpl.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -295,7 +296,10 @@ void QNetworkReplyWasmImplPrivate::doSendRequest() QByteArray destinationPath = dPath.toUtf8(); attr.destinationPath = destinationPath.constData(); - m_fetch = emscripten_fetch(&attr, request.url().toString().toUtf8()); + auto url = request.url().toString().toUtf8(); + QEventDispatcherWasm::runOnMainThreadAsync([attr, url]() mutable { + emscripten_fetch(&attr, url); + }); state = Working; }