Skip to content

Commit

Permalink
Merge pull request #714 from intechstudio/bug/Alive
Browse files Browse the repository at this point in the history
🚩PR: Fixed bug of runtime error when connecting/reconnecting many modules
  • Loading branch information
SukuWc authored May 7, 2024
2 parents 79f8dec + d619f3b commit e219b29
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/renderer/runtime/runtime.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,26 @@ function create_runtime() {
});
}

let lastDate = get(heartbeat).find(
const lastDate = get(heartbeat).find(
(device) => device.id == controller.id
).alive;
let newDate = Date.now();
get(heartbeat).find((device) => device.id == controller.id).alive =
newDate;
)?.alive;
if (lastDate) {
let newDate = Date.now();

heartbeat.update((store) => {
const device = store.find((device) => device.id == controller.id);
if (device) {
device.alive = newDate;
}
return store;
});

//console.log(newDate - lastDate)
if (get(appSettings).persistent.heartbeatDebugEnabled) {
const key1 = `Hearbeat (${controller.dx}, ${controller.dy})`;
//console.log(newDate - lastDate)
if (get(appSettings).persistent.heartbeatDebugEnabled) {
const key1 = `Hearbeat (${controller.dx}, ${controller.dy})`;

add_datapoint(key1, newDate - lastDate);
add_datapoint(key1, newDate - lastDate);
}
}
}
// device not found, add it to runtime and get page count from grid
Expand Down Expand Up @@ -1212,7 +1220,7 @@ const grid_heartbeat_interval_handler = async function () {
return;
}

const alive = get(heartbeat).find((e) => e.id == device.id).alive;
const alive = get(heartbeat).find((e) => e.id == device.id)?.alive;

// Allow less strict elapsedTimeLimit while writeBuffer is busy!
const elapsedTimeLimit =
Expand All @@ -1221,7 +1229,7 @@ const grid_heartbeat_interval_handler = async function () {
: heartbeat_grid_ms * 3;
const elapsedTime = Date.now() - alive;

if (elapsedTime > elapsedTimeLimit) {
if (!alive || elapsedTime > elapsedTimeLimit) {
// TIMEOUT! let's remove the device
runtime.destroy_module(device.dx, device.dy);
heartbeat.update((heartbeat) => {
Expand Down

0 comments on commit e219b29

Please sign in to comment.