From ba3a247e492c564c4975745df4ae62b4d428c056 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Mon, 29 Apr 2024 19:20:17 +0200 Subject: [PATCH] Fix crashes related to the request ID generation --- svr.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/svr.js b/svr.js index 8fe8bd2..b8cee5f 100644 --- a/svr.js +++ b/svr.js @@ -2032,7 +2032,8 @@ if (!cluster.isPrimary) { }); if (!disableToHTTPSRedirect) { server2.on("connect", function (request, socket) { - var reqIdInt = Math.round(Math.random() * 16777216); + var reqIdInt = Math.floor(Math.random() * 16777216); + if (reqIdInt == 16777216) reqIdInt = 0; var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16); var serverconsole = { climessage: function (msg) { @@ -2327,7 +2328,8 @@ if (!cluster.isPrimary) { res.write(head); }; - var reqIdInt = Math.round(Math.random() * 16777216); + var reqIdInt = Math.floor(Math.random() * 16777216); + if (reqIdInt == 16777216) reqIdInt = 0; var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16); var serverconsole = { climessage: function (msg) { @@ -2679,7 +2681,8 @@ if (!cluster.isPrimary) { } function connhandler(request, socket, head) { - var reqIdInt = Math.round(Math.random() * 16777216); + var reqIdInt = Math.floor(Math.random() * 16777216); + if (reqIdInt == 16777216) reqIdInt = 0; var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16); var serverconsole = { climessage: function (msg) { @@ -2798,7 +2801,8 @@ if (!cluster.isPrimary) { function reqhandler(req, res, fromMain) { if (fromMain === undefined) fromMain = true; - var reqIdInt = Math.round(Math.random() * 16777216); + var reqIdInt = Math.floor(Math.random() * 16777216); + if (reqIdInt == 16777216) reqIdInt = 0; var reqId = "0".repeat(6 - reqIdInt.toString(16).length) + reqIdInt.toString(16); var serverconsole = { climessage: function (msg) {