@mongosh/node-runtime-worker-thread 1.6.0 → 1.6.1
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/dist/child-process-proxy.js +2 -1
- package/dist/child-process-proxy.js.LICENSE.txt +14 -0
- package/dist/child-process-proxy.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.LICENSE.txt +14 -0
- package/dist/worker-runtime.js +155 -155
- package/package.json +8 -8
- package/src/child-process-proxy.spec.ts +38 -2
- package/src/child-process-proxy.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongosh/node-runtime-worker-thread",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "MongoDB shell runtime that lives in a worker thread",
|
|
5
5
|
"homepage": "https://github.com/mongodb-js/mongosh",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -28,22 +28,22 @@
|
|
|
28
28
|
"prepublish": "npm run webpack-build"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@mongosh/browser-runtime-core": "1.6.
|
|
32
|
-
"@mongosh/browser-runtime-electron": "1.6.
|
|
33
|
-
"@mongosh/service-provider-core": "1.6.
|
|
34
|
-
"@mongosh/service-provider-server": "1.6.
|
|
35
|
-
"@mongosh/types": "1.6.
|
|
31
|
+
"@mongosh/browser-runtime-core": "1.6.1",
|
|
32
|
+
"@mongosh/browser-runtime-electron": "1.6.1",
|
|
33
|
+
"@mongosh/service-provider-core": "1.6.1",
|
|
34
|
+
"@mongosh/service-provider-server": "1.6.1",
|
|
35
|
+
"@mongosh/types": "1.6.1",
|
|
36
36
|
"bson": "^4.7.0",
|
|
37
37
|
"mocha": "^7.1.2",
|
|
38
38
|
"postmsg-rpc": "^2.4.0",
|
|
39
39
|
"terser-webpack-plugin": "^4.2.3",
|
|
40
40
|
"ts-loader": "^8.0.14",
|
|
41
|
-
"webpack": "^
|
|
41
|
+
"webpack": "^5.75.0",
|
|
42
42
|
"webpack-cli": "^4.3.1"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"interruptor": "^1.0.1",
|
|
46
46
|
"system-ca": "^1.0.2"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "51c067456d3e0127156ef1722a44659151e01a12"
|
|
49
49
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { ChildProcess, fork } from 'child_process';
|
|
2
|
+
import { ChildProcess, fork, spawn } from 'child_process';
|
|
3
3
|
import { Caller, cancel, createCaller } from './rpc';
|
|
4
4
|
import { expect } from 'chai';
|
|
5
5
|
import { WorkerRuntime } from './worker-runtime';
|
|
6
|
+
import { once } from 'events';
|
|
7
|
+
import { promisify } from 'util';
|
|
6
8
|
|
|
7
9
|
const childProcessModulePath = path.resolve(
|
|
8
10
|
__dirname,
|
|
@@ -22,7 +24,7 @@ describe('child process worker proxy', () => {
|
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
if (childProcess) {
|
|
25
|
-
childProcess.
|
|
27
|
+
childProcess.disconnect();
|
|
26
28
|
childProcess = null;
|
|
27
29
|
}
|
|
28
30
|
});
|
|
@@ -34,4 +36,38 @@ describe('child process worker proxy', () => {
|
|
|
34
36
|
const result = await caller.evaluate('1 + 1');
|
|
35
37
|
expect(result.printable).to.equal(2);
|
|
36
38
|
});
|
|
39
|
+
|
|
40
|
+
it('should exit on its own when the parent process disconnects', async() => {
|
|
41
|
+
const intermediateProcess = spawn(process.execPath,
|
|
42
|
+
['-e', `require("child_process")
|
|
43
|
+
.fork(${JSON.stringify(childProcessModulePath)})
|
|
44
|
+
.on("message", function(m) { console.log("message " + m + " from " + this.pid) })`],
|
|
45
|
+
{ stdio: ['pipe', 'pipe', 'inherit'] });
|
|
46
|
+
|
|
47
|
+
// Make sure the outer child process runs and has created the inner child process
|
|
48
|
+
const [message] = await once(intermediateProcess.stdout.setEncoding('utf8'), 'data');
|
|
49
|
+
const match = message.trim().match(/^message ready from (?<pid>\d+)$/);
|
|
50
|
+
expect(match).to.not.equal(null);
|
|
51
|
+
|
|
52
|
+
// Make sure the inner child process runs
|
|
53
|
+
const childPid = +match.groups.pid;
|
|
54
|
+
process.kill(childPid, 0);
|
|
55
|
+
|
|
56
|
+
// Kill the intermediate process and wait for the inner child process to also close
|
|
57
|
+
intermediateProcess.kill('SIGTERM');
|
|
58
|
+
let innerChildHasStoppedRunning = false;
|
|
59
|
+
for (let i = 0; i < 200; i++) {
|
|
60
|
+
try {
|
|
61
|
+
process.kill(childPid, 0);
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (err.code === 'ESRCH') {
|
|
64
|
+
innerChildHasStoppedRunning = true;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
await promisify(setTimeout)(10);
|
|
70
|
+
}
|
|
71
|
+
expect(innerChildHasStoppedRunning).to.equal(true);
|
|
72
|
+
});
|
|
37
73
|
});
|
|
@@ -114,6 +114,7 @@ const messageBus = createCaller(['emit', 'on'], process);
|
|
|
114
114
|
|
|
115
115
|
exposeAll(messageBus, workerProcess);
|
|
116
116
|
|
|
117
|
+
process.once('disconnect', () => process.exit());
|
|
117
118
|
process.nextTick(() => {
|
|
118
119
|
// eslint-disable-next-line chai-friendly/no-unused-expressions
|
|
119
120
|
process.send?.('ready');
|