@remix_labs/machine-starter 2.13008.0-dev → 2.13012.0
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 +52 -47
- package/groovebox_build.js +1 -1
- package/package.json +2 -2
package/common.js
CHANGED
|
@@ -21,9 +21,8 @@ class TaskQueue {
|
|
|
21
21
|
}
|
|
22
22
|
run(fn) { // fn shall return a promise. run also returns a promise
|
|
23
23
|
this.length++;
|
|
24
|
-
const result = this.tail.then(() => fn());
|
|
24
|
+
const result = this.tail.then(() => fn()).finally(() => { this.length--; });
|
|
25
25
|
this.tail = result.catch(() => {});
|
|
26
|
-
this.length--;
|
|
27
26
|
return result;
|
|
28
27
|
}
|
|
29
28
|
}
|
|
@@ -68,50 +67,54 @@ function getCoord(vmID) {
|
|
|
68
67
|
|
|
69
68
|
async function terminateVM(vmID) {
|
|
70
69
|
let coord = getCoord(vmID);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
70
|
+
try {
|
|
71
|
+
await coord.queue.run(async () => {
|
|
72
|
+
if (!workers[vmID]) return;
|
|
73
|
+
console.log("[machine-starter] terminate VM:", vmID);
|
|
74
|
+
// make the VM first unknown to the outside and disconnect it,
|
|
75
|
+
// then clean up resources (including stopping the VM)
|
|
76
|
+
let channel = await last_hub.newChannel();
|
|
77
|
+
let topic = worker_topics[vmID];
|
|
78
|
+
let payload = { _rmx_type:"msg_vm_register", id: vmID, alive: false };
|
|
79
|
+
let msg = channel.newJSONMessage("msg_vm_register", "vm", payload);
|
|
80
|
+
await channel.publish(topic + "/announce", msg, true);
|
|
81
|
+
// NB. This msg is a leak - it will never be removed.
|
|
82
|
+
await channel.disconnect("vm_" + vmID);
|
|
83
|
+
// now the VM is isolated and cannot communicate with the
|
|
84
|
+
// hub anymore
|
|
85
|
+
let worker = workers[vmID];
|
|
86
|
+
let vmChildren = children[vmID] || [];
|
|
87
|
+
let blobList = blobs[vmID] || [];
|
|
88
|
+
let ffiLoop = ffiLoops[vmID];
|
|
89
|
+
let blobsLoop = blobsLoops[vmID];
|
|
90
|
+
delete children[vmID];
|
|
91
|
+
delete ffiLoops[vmID];
|
|
92
|
+
delete blobsLoops[vmID];
|
|
93
|
+
delete worker_topics[vmID];
|
|
94
|
+
delete workers[vmID];
|
|
95
|
+
// terminate our endpoints of communication
|
|
96
|
+
if (ffiLoop) {
|
|
97
|
+
ffiLoop.terminate();
|
|
98
|
+
}
|
|
99
|
+
if (blobsLoop) {
|
|
100
|
+
blobsLoop.terminate();
|
|
101
|
+
}
|
|
102
|
+
for (let blob_url of blobList) {
|
|
103
|
+
console.log("[machine-starter] revoke ", blob_url);
|
|
104
|
+
URL.revokeObjectURL(blob_url);
|
|
105
|
+
}
|
|
106
|
+
// kill the worker:
|
|
107
|
+
console.log("[machine-starter] terminate web worker for VM:", vmID);
|
|
108
|
+
worker.terminate();
|
|
109
|
+
// go on with sub VMs
|
|
110
|
+
for (let subID of vmChildren) {
|
|
111
|
+
terminateVM(subID) // do not wait
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
} finally {
|
|
115
|
+
if (coord.queue.length == 0 && coordination[vmID] === coord) {
|
|
116
|
+
delete coordination[vmID];
|
|
111
117
|
}
|
|
112
|
-
});
|
|
113
|
-
if (coord.queue.length == 0) {
|
|
114
|
-
delete coordination[vmID];
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
|
|
@@ -167,9 +170,11 @@ async function StartWASM2(hub, config, getWorker) {
|
|
|
167
170
|
console.log("[machine-starter] Call MixExplain() for explaining debug levels, and MixSetMask(m) for changing these")
|
|
168
171
|
};
|
|
169
172
|
last_hub = hub;
|
|
170
|
-
// get
|
|
173
|
+
// get the coord object - perhaps the ID was already used for a VM
|
|
171
174
|
let coord = getCoord(config.vmID);
|
|
172
|
-
await coord.queue.run(async () => {
|
|
175
|
+
return await coord.queue.run(async () => {
|
|
176
|
+
if (workers[config.vmID])
|
|
177
|
+
throw new Error("[machine-starter] Cannot start VM, the ID is used: " + config.vmID);
|
|
173
178
|
let channel = await hub.newChannel("vm_" + config.vmID);
|
|
174
179
|
// injected by either index.js or node.js
|
|
175
180
|
let worker = await getWorker();
|
package/groovebox_build.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var GROOVEBOX_BUILD = "
|
|
1
|
+
var GROOVEBOX_BUILD = "13012";
|
|
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.13012.0",
|
|
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.13012.0",
|
|
15
15
|
"nanoid": "^5.0.2",
|
|
16
16
|
"web-worker": "^1.2.0"
|
|
17
17
|
},
|