diff --git a/server/package-lock.json b/server/package-lock.json index 680c34f43..59880896c 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/server", - "version": "0.115.38", + "version": "0.115.39", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/server", - "version": "0.115.38", + "version": "0.115.39", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/server/src/plugin/runtime/node-fork-worker.ts b/server/src/plugin/runtime/node-fork-worker.ts index 11df338f3..55fc6ef10 100644 --- a/server/src/plugin/runtime/node-fork-worker.ts +++ b/server/src/plugin/runtime/node-fork-worker.ts @@ -4,6 +4,7 @@ import { RpcMessage, RpcPeer } from "../../rpc"; import { SidebandSocketSerializer } from "../socket-serializer"; import { ChildProcessWorker } from "./child-process-worker"; import { RuntimeWorkerOptions } from "./runtime-worker"; +import worker_threads from 'worker_threads'; export class NodeForkWorker extends ChildProcessWorker { @@ -17,7 +18,10 @@ export class NodeForkWorker extends ChildProcessWorker { execArgv.push(`--inspect=0.0.0.0:${pluginDebug.inspectPort}`); } - this.worker = child_process.fork(mainFilename, ['child', this.pluginId], { + this.worker = child_process.fork(mainFilename, [ + worker_threads.isMainThread ? 'child' : 'fork', + this.pluginId + ], { stdio: ['pipe', 'pipe', 'pipe', 'ipc'], env: Object.assign({}, process.env, env), serialization: 'advanced', diff --git a/server/src/scrypted-main-exports.ts b/server/src/scrypted-main-exports.ts index 4531b07d3..9e169cad6 100644 --- a/server/src/scrypted-main-exports.ts +++ b/server/src/scrypted-main-exports.ts @@ -12,7 +12,7 @@ import { RPCResultError, startPeriodicGarbageCollection } from './rpc'; import type { Runtime } from './scrypted-server-main'; export function isChildProcess() { - return process.argv[2] === 'child' || process.argv[2] === 'child-thread' + return process.argv[2] === 'child' || process.argv[2] === 'fork' || process.argv[2] === 'child-thread'; } function start(mainFilename: string, options?: { @@ -42,7 +42,7 @@ function start(mainFilename: string, options?: { startPeriodicGarbageCollection(); - if (process.argv[2] === 'child' || process.argv[2] === 'child-thread') { + if (isChildProcess()) { // plugins should never crash. this handler will be removed, and then readded // after the plugin source map is retrieved. process.on('uncaughtException', e => {