Skip to content

Commit

Permalink
Add a watchdog to detect crashed wasm builds and reload the page
Browse files Browse the repository at this point in the history
Fixes #1803
  • Loading branch information
DanielMcInnes committed Dec 20, 2024
1 parent e4b8b6c commit e0f4770
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
28 changes: 25 additions & 3 deletions .github/patches/index.html.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
diff -u index.html venus-gui-v2.html
--- index.html 2024-05-16 22:12:44.106129598 +0300
+++ venus-gui-v2.html 2024-07-05 12:44:44.396192697 +0200
--- venus-gui-v2.html 2024-12-19 11:52:03.677046276 +1000
+++ index.html 2024-12-19 13:54:58.232268241 +1000
@@ -12,15 +12,18 @@
<title>venus-gui-v2</title>
<style>
Expand Down Expand Up @@ -63,3 +62,26 @@ diff -u index.html venus-gui-v2.html
qt: {
onLoaded: () => showUi(screen),
onExit: exitData =>
@@ -70,5 +99,22 @@
</script>
<script src="venus-gui-v2.js"></script>
<script type="text/javascript" src="qtloader.js"></script>
+ <script type="text/javascript">
+ var watchdogHit = false // this gets set to 'true' by a timer via BackendConnection::hitWatchdog()
+ console.log("starting watchdog timer")
+ setTimeout(function(){ // wait 2 minutes for the page to load, then set a 10 second watchdog timer
+ checkWatchdog()
+ setInterval(checkWatchdog, 10000)
+ }, 120000)
+
+ function checkWatchdog()
+ {
+ if (!watchdogHit) {
+ console.error("Watchdog timer expired - reloading page")
+ location.reload()
+ }
+ watchdogHit = false
+ }
+ </script>
</body>
</html>
8 changes: 8 additions & 0 deletions ApplicationContent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,12 @@ Item {
? "qrc:/qt/qml/Victron/VenusOS/components/InputPanel.qml"
: "qrc:/qt/qml/Victron/VenusOS/components/WasmVirtualKeyboardHandler.qml"
}

// Sometimes, the wasm code may crash. Use a watchdog to detect this and reload the page when necessary.
Timer {
running: Qt.platform.os === "wasm" && BackendConnection.state === BackendConnection.Ready
repeat: true
interval: 1000
onTriggered: BackendConnection.hitWatchdog()
}
}
5 changes: 5 additions & 0 deletions src/backendconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ void BackendConnection::openUrl(const QString &url)
emscripten_run_script(ba.constData());
}

void BackendConnection::hitWatchdog()
{
emscripten_run_script("watchdogHit = true"); // 'watchdogHit' is defined in index.html, which checks it periodically and reloads the page if not hit regularly.
}

#else

void BackendConnection::onNetworkConfigChanged(const QVariant var) { Q_UNUSED(var); }
Expand Down
3 changes: 3 additions & 0 deletions src/backendconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class BackendConnection : public QObject
// Move this to some mock data manager when available
Q_INVOKABLE void setMockValue(const QString &uid, const QVariant &value);
Q_INVOKABLE QVariant mockValue(const QString &uid) const;
#if defined(VENUS_WEBASSEMBLY_BUILD)
Q_INVOKABLE void hitWatchdog();
#endif

Q_SIGNALS:
void stateChanged();
Expand Down

0 comments on commit e0f4770

Please sign in to comment.