1
0
Fork 0
forked from svrjs/svrjs

Add warning about worker count limited to one when using Bun 1.0 and newer with shimmed (not native) clustering module.

This commit is contained in:
Dorian Niemiec 2023-09-10 19:30:29 +02:00
parent 7973dafa60
commit e828bb9173
2 changed files with 36 additions and 14 deletions

View file

@ -3,7 +3,7 @@
"port": 80,
"pubport": 80,
"page404": "404.html",
"timestamp": 1694365365939,
"timestamp": 1694366855651,
"blacklist": [],
"nonStandardCodes": [],
"enableCompression": true,

22
svr.js
View file

@ -151,6 +151,7 @@ if (!singlethreaded) {
cluster.isMaster = !process.env.NODE_UNIQUE_ID;
cluster.isPrimary = cluster.isMaster;
cluster.isWorker = !cluster.isMaster;
cluster.__shimmed__ = true;
if (cluster.isWorker) {
// Shim the cluster.worker object for worker processes
@ -329,6 +330,7 @@ var SVRJSInitialized = false;
var exiting = false;
var reallyExiting = false;
var crashed = false;
var threadLimitWarned = false;
function SVRJSFork() {
// Log
@ -336,16 +338,35 @@ function SVRJSFork() {
// Fork new worker
var newWorker = {};
try {
if (cluster.__shimmed__ && process.isBun && process.versions.bun && process.versions.bun[0] != "0" && !threadLimitWarned) {
threadLimitWarned = true;
serverconsole.locwarnmessage("SVR.JS limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.");
}
if (!(cluster.__shimmed__ && process.isBun && process.versions.bun && process.versions.bun[0] != "0" && Object.keys(cluster.workers) > 0)) {
newWorker = cluster.fork();
} else {
if (SVRJSInitialized) serverconsole.locwarnmessage("SVR.JS limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.");
}
} catch (err) {
if(err.name == "NotImplementedError") {
// If cluster.fork throws a NotImplementedError, shim cluster module
cluster.bunShim();
if (cluster.__shimmed__ && process.isBun && process.versions.bun && process.versions.bun[0] != "0" && !threadLimitWarned) {
threadLimitWarned = true;
serverconsole.locwarnmessage("SVR.JS limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.");
}
if (!(cluster.__shimmed__ && process.isBun && process.versions.bun && process.versions.bun[0] != "0" && Object.keys(cluster.workers) > 0)) {
newWorker = cluster.fork();
} else {
if (SVRJSInitialized) serverconsole.locwarnmessage("SVR.JS limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.");
}
} else {
throw err;
}
}
// Add event listeners
if(newWorker.on) {
newWorker.on("error", function (err) {
if(!reallyExiting) serverconsole.locwarnmessage("There was a problem when handling SVR.JS worker! (from master process side) Reason: " + err.message);
});
@ -358,6 +379,7 @@ function SVRJSFork() {
newWorker.on("message", bruteForceListenerWrapper(newWorker));
newWorker.on("message", listenConnListener);
}
}
var http = require("http");
http.STATUS_CODES[497] = "HTTP Request Sent to HTTPS Port";