From d0a01ebe180207729ee3fc6bf81d52e73aed3f3f Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Mon, 11 Sep 2023 23:43:53 +0200 Subject: [PATCH] Update to SVR.JS 3.4.35 --- index.html | 15 ++++++--------- licenses/index.html | 8 ++++---- serverSideScript.js | 4 ++-- svr.js | 30 ++++++++++++++++++++++++++---- tests.html | 4 ++-- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/index.html b/index.html index eb38a18..9ffa673 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,7 @@ - SVR.JS 3.4.34 + SVR.JS 3.4.35 -

Welcome to SVR.JS 3.4.34

+

Welcome to SVR.JS 3.4.35



@@ -74,7 +74,7 @@           "replacement": ""
        }
      ]
-     },
3.4.13 +     },
    {
      "definingRegex": "/^\\/invoke500\\/.+/",
      "replacements": [
@@ -119,12 +119,9 @@

Changes:

-

Bugs:

-
Tests
diff --git a/licenses/index.html b/licenses/index.html index 3c2b7da..f8d92e3 100644 --- a/licenses/index.html +++ b/licenses/index.html @@ -1,7 +1,7 @@ - SVR.JS 3.4.34 Licenses + SVR.JS 3.4.35 Licenses -

SVR.JS 3.4.34 Licenses

-

SVR.JS 3.4.34

+

SVR.JS 3.4.35 Licenses

+

SVR.JS 3.4.35

MIT License

@@ -37,7 +37,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-

Packages used by SVR.JS 3.4.34 and utilities

+

Packages used by SVR.JS 3.4.35 and utilities

License: MIT
diff --git a/serverSideScript.js b/serverSideScript.js index 255ae32..a362f05 100644 --- a/serverSideScript.js +++ b/serverSideScript.js @@ -9,12 +9,12 @@ // ext - File extension of requested file // uobject - Request URL object // search - Request URL queries -// defaultPage - An index page location (deprecated, always returns 'index.json') +// defaultPage - An index page location (deprecated, always returns 'index.html') // users - A list of users (deprecated) // page404 - 404 Not Found page location // head - A head of server response // foot - A foot of server response -// fd - A response body used by responseEnd method +// fd - Currently unused // elseCallback - Method summoning SVR.JS internal callbacks // callServerError - Method to end with server error // getCustomHeaders - Method to get headers defined in config.json file diff --git a/svr.js b/svr.js index ca3d04c..885970f 100644 --- a/svr.js +++ b/svr.js @@ -71,7 +71,7 @@ function deleteFolderRecursive(path) { } var os = require("os"); -var version = "3.4.34"; +var version = "3.4.35"; var singlethreaded = false; if (process.versions) process.versions.svrjs = version; //Inject SVR.JS into process.versions @@ -142,6 +142,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 @@ -279,6 +280,10 @@ if (!singlethreaded) { newWorker.send(message, fakeParam2, fakeParam3, fakeParam4, tries + 1); } }; + } else { + newWorker.on("exit", function () { + delete cluster.workers[newWorker.id]; + }); } cluster.workers[newWorker.id] = newWorker; @@ -300,6 +305,7 @@ var bruteForceDb = {}; var SVRJSInitialized = false; var exiting = false; var crashed = false; +var threadLimitWarned = false; function SVRJSFork() { //Log @@ -307,12 +313,28 @@ function SVRJSFork() { //Fork new worker var newWorker = {}; try { - newWorker = cluster.fork(); + if (!threadLimitWarned && cluster.__shimmed__ && process.isBun && process.versions.bun && process.versions.bun[0] != "0") { + 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(); - newWorker = cluster.fork(); + if (!threadLimitWarned && cluster.__shimmed__ && process.isBun && process.versions.bun && process.versions.bun[0] != "0") { + 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; } @@ -1252,7 +1274,7 @@ if (!disableMods) { modloaderFolderName = ".modloader_w" + Math.floor(Math.random() * 65536); } var tempServerSideScriptName = "serverSideScript.js"; - if (!process.isBun && cluster.isPrimary === false) { + if (!(process.isBun && process.versions.bun && process.versions.bun[0] == "0") && cluster.isPrimary === false) { tempServerSideScriptName = ".serverSideScript_w" + Math.floor(Math.random() * 65536) + ".js"; } for (var i = 0; i < modFiles.length; i++) { diff --git a/tests.html b/tests.html index 31e6ca6..850863d 100644 --- a/tests.html +++ b/tests.html @@ -1,7 +1,7 @@ - SVR.JS 3.4.34 Tests + SVR.JS 3.4.35 Tests -

SVR.JS 3.4.34 Tests

+

SVR.JS 3.4.35 Tests

Directory

Directory (with query)