@remix_labs/machine-starter 2.13052.0 → 2.13056.0-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common.js +43 -4
- package/groovebox_build.js +1 -1
- package/package.json +2 -2
package/common.js
CHANGED
|
@@ -77,9 +77,14 @@ async function terminateVM(vmID) {
|
|
|
77
77
|
let topic = worker_topics[vmID];
|
|
78
78
|
let payload = { _rmx_type:"msg_vm_register", id: vmID, alive: false };
|
|
79
79
|
let msg = channel.newJSONMessage("msg_vm_register", "vm", payload);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
try {
|
|
81
|
+
await channel.publish(topic + "/announce", msg, true);
|
|
82
|
+
// NB. This msg is a leak - it will never be removed.
|
|
83
|
+
await channel.disconnect("vm_" + vmID);
|
|
84
|
+
} finally {
|
|
85
|
+
// this channel is only used here: release the hub's end of it
|
|
86
|
+
closeChannel(channel);
|
|
87
|
+
}
|
|
83
88
|
// now the VM is isolated and cannot communicate with the
|
|
84
89
|
// hub anymore
|
|
85
90
|
let worker = workers[vmID];
|
|
@@ -118,6 +123,16 @@ async function terminateVM(vmID) {
|
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
125
|
|
|
126
|
+
// A hub channel has no explicit close: drop its MessagePort so the hub worker can release it.
|
|
127
|
+
function closeChannel(channel) {
|
|
128
|
+
try {
|
|
129
|
+
if (typeof channel.close === "function") channel.close();
|
|
130
|
+
else channel.port && channel.port.close && channel.port.close();
|
|
131
|
+
// a message sent just before close() may not arrive: ask via the hub itself as well
|
|
132
|
+
if (last_hub && last_hub.closeChannelById) last_hub.closeChannelById(channel.chanId);
|
|
133
|
+
} catch (_) {}
|
|
134
|
+
}
|
|
135
|
+
|
|
121
136
|
if (globalThis.Process) {
|
|
122
137
|
Process.on("exit", () => {
|
|
123
138
|
terminateAllOnExit()
|
|
@@ -275,6 +290,7 @@ async function ffi_vm_start(conn, args, getWorker) {
|
|
|
275
290
|
let vmChildren = children[conn.config.vmID];
|
|
276
291
|
if (!vmChildren) vmChildren = [];
|
|
277
292
|
vmChildren.push(vm_id);
|
|
293
|
+
children[conn.config.vmID] = vmChildren; // was never stored: embedded VMs were not stopped with their parent
|
|
278
294
|
let arg_config = args[0];
|
|
279
295
|
if (arg_config.interceptFFI !== undefined)
|
|
280
296
|
config["interceptFFI"] = arg_config.interceptFFI;
|
|
@@ -288,6 +304,10 @@ async function ffi_vm_stop(conn, args) {
|
|
|
288
304
|
let vm_id = args[0];
|
|
289
305
|
let worker = workers[vm_id];
|
|
290
306
|
if (!worker) throw new Error("no such VM: " + vm_id);
|
|
307
|
+
for (let parent of Object.keys(children)) {
|
|
308
|
+
let i = children[parent].indexOf(vm_id);
|
|
309
|
+
if (i >= 0) children[parent].splice(i, 1);
|
|
310
|
+
}
|
|
291
311
|
terminateVM(vm_id);
|
|
292
312
|
return null;
|
|
293
313
|
}
|
|
@@ -430,6 +450,10 @@ async function starterFFIsMessageLoop(hub, config, starterFFIs, terminate) {
|
|
|
430
450
|
]);
|
|
431
451
|
if (terminated || msg.eof) {
|
|
432
452
|
// console.log("[machine-starter] terminate FFI loop", vmID);
|
|
453
|
+
// Release the hub subscription and channel; without this each VM (one per build in the
|
|
454
|
+
// builder) left both behind for the lifetime of the page.
|
|
455
|
+
await sub.unsubscribe().catch(() => {});
|
|
456
|
+
closeChannel(channel);
|
|
433
457
|
return;
|
|
434
458
|
}
|
|
435
459
|
let name = msg.payload.name;
|
|
@@ -490,6 +514,8 @@ async function blobsMessageLoop(hub, config, terminate) {
|
|
|
490
514
|
]);
|
|
491
515
|
if (terminated || msg.eof) {
|
|
492
516
|
// console.log("[machine-starter] terminate blobs loop", vmID);
|
|
517
|
+
await sub.unsubscribe().catch(() => {});
|
|
518
|
+
closeChannel(channel);
|
|
493
519
|
return;
|
|
494
520
|
}
|
|
495
521
|
let name = msg.payload.name;
|
|
@@ -557,7 +583,20 @@ class FFIComm {
|
|
|
557
583
|
}
|
|
558
584
|
}
|
|
559
585
|
|
|
586
|
+
// Stops every VM that `parentVmID` started (through $vm_start) and has not stopped itself, including
|
|
587
|
+
// ones that are still starting. Returns how many were stopped. A parent that outlives its children
|
|
588
|
+
// (the L2 session agent starts one embedded VM per session) can leave one running when its owner
|
|
589
|
+
// goes away before the session finished starting; the caller decides when that has happened.
|
|
590
|
+
function terminateChildren(parentVmID) {
|
|
591
|
+
let list = children[parentVmID];
|
|
592
|
+
if (!list || list.length === 0) return 0;
|
|
593
|
+
let ids = list.slice();
|
|
594
|
+
children[parentVmID] = [];
|
|
595
|
+
for (let id of ids) terminateVM(id);
|
|
596
|
+
return ids.length;
|
|
597
|
+
}
|
|
598
|
+
|
|
560
599
|
// use terminateVM to shut a worker down!
|
|
561
|
-
export { StartWASM, StartWASM2, terminateVM,
|
|
600
|
+
export { StartWASM, StartWASM2, terminateVM, terminateChildren,
|
|
562
601
|
Token, Case, Opaque
|
|
563
602
|
}
|
package/groovebox_build.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var GROOVEBOX_BUILD = "
|
|
1
|
+
var GROOVEBOX_BUILD = "13056";
|
|
2
2
|
export { GROOVEBOX_BUILD }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix_labs/machine-starter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13056.0-dev",
|
|
4
4
|
"description": "start the groove",
|
|
5
5
|
"main": "node.js",
|
|
6
6
|
"browser": "index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"author": "Remixlabs staff",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@remix_labs/hub-client": "2.
|
|
14
|
+
"@remix_labs/hub-client": "2.13056.0-dev",
|
|
15
15
|
"nanoid": "^5.0.2",
|
|
16
16
|
"web-worker": "^1.2.0"
|
|
17
17
|
},
|