aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2020-01-08 07:59:14 -0500
committerSam Wilkins <samwilkins333@gmail.com>2020-01-08 07:59:14 -0500
commit3b16e5e94daf370032fb521004fa9618131cb46f (patch)
tree508665c4eb1947079a1ca664e69a2c00d5bab6ff /src
parentea4d32815b478f0f8c8573b3f73b179c7324a220 (diff)
more robust factory constraints
Diffstat (limited to 'src')
-rw-r--r--src/server/Session/session.ts19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/server/Session/session.ts b/src/server/Session/session.ts
index 144d50c52..936357364 100644
--- a/src/server/Session/session.ts
+++ b/src/server/Session/session.ts
@@ -1,5 +1,5 @@
import { red, cyan, green, yellow, magenta, blue, white } from "colors";
-import { on, fork, setupMaster, Worker, isMaster } from "cluster";
+import { on, fork, setupMaster, Worker, isMaster, isWorker } from "cluster";
import { get } from "request-promise";
import { Utils } from "../../Utils";
import Repl, { ReplAction } from "../repl";
@@ -120,9 +120,13 @@ export namespace Session {
private key: string | undefined;
private repl: Repl;
- public static Create(notifiers: Monitor.NotifierHooks) {
- if (++Monitor.count > 1) {
- throw new Error("Cannot create more than one monitor");
+ public static Create(notifiers?: Monitor.NotifierHooks) {
+ if (isWorker) {
+ console.error(red("Monitor must be on the master process."));
+ process.exit(1);
+ } else if (++Monitor.count > 1) {
+ console.error(("Cannot create more than one monitor."));
+ process.exit(1);
} else {
return new Monitor(notifiers);
}
@@ -438,8 +442,11 @@ export namespace Session {
private serverPort: number;
public static Create(work: Function) {
- if (++ServerWorker.count > 1) {
- throw new Error("Cannot create more than one worker per thread");
+ if (isMaster) {
+ throw new Error("Worker must be launched on a worker process.");
+ } else if (++ServerWorker.count > 1 || isMaster) {
+ process.send?.({ action: { message: "kill", args: { graceful: false } } });
+ process.exit(1);
} else {
return new ServerWorker(work);
}