forked from svrjs/svrjs
Fix cluster NotImplementedError when running SVR.JS on newer versions of Bun.
This commit is contained in:
parent
3d4acae311
commit
7cc4dbf4d2
1 changed files with 19 additions and 2 deletions
21
svr.js
21
svr.js
|
@ -146,8 +146,10 @@ if (!singlethreaded) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cluster & IPC shim for Bun
|
// Cluster & IPC shim for Bun
|
||||||
if (process.isBun && cluster.isMaster === undefined) {
|
|
||||||
|
cluster.bunShim = function () {
|
||||||
cluster.isMaster = !process.env.NODE_UNIQUE_ID;
|
cluster.isMaster = !process.env.NODE_UNIQUE_ID;
|
||||||
|
cluster.isPrimary = cluster.isMaster;
|
||||||
cluster.isWorker = !cluster.isMaster;
|
cluster.isWorker = !cluster.isMaster;
|
||||||
|
|
||||||
if (cluster.isWorker) {
|
if (cluster.isWorker) {
|
||||||
|
@ -274,6 +276,10 @@ if (!singlethreaded) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.isBun && cluster.isMaster === undefined) {
|
||||||
|
cluster.bunShim();
|
||||||
|
}
|
||||||
|
|
||||||
// Shim cluster.isPrimary field
|
// Shim cluster.isPrimary field
|
||||||
if (cluster.isPrimary === undefined && cluster.isMaster !== undefined) cluster.isPrimary = cluster.isMaster;
|
if (cluster.isPrimary === undefined && cluster.isMaster !== undefined) cluster.isPrimary = cluster.isMaster;
|
||||||
}
|
}
|
||||||
|
@ -298,7 +304,18 @@ function SVRJSFork() {
|
||||||
//Log
|
//Log
|
||||||
if (SVRJSInitialized) serverconsole.locmessage("Starting next thread, because previous one hung up/crashed...");
|
if (SVRJSInitialized) serverconsole.locmessage("Starting next thread, because previous one hung up/crashed...");
|
||||||
//Fork new worker
|
//Fork new worker
|
||||||
var newWorker = cluster.fork();
|
var newWorker = {};
|
||||||
|
try {
|
||||||
|
newWorker = cluster.fork();
|
||||||
|
} catch (err) {
|
||||||
|
if(err.name == "NotImplementedError") {
|
||||||
|
// If cluster.fork throws a NotImplementedError, shim cluster module
|
||||||
|
cluster.bunShim();
|
||||||
|
newWorker = cluster.fork();
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
newWorker.on("error", function (err) {
|
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);
|
if(!reallyExiting) serverconsole.locwarnmessage("There was a problem when handling SVR.JS worker! (from master process side) Reason: " + err.message);
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue