forked from svrjs/svrjs
Fix Bun cluster shim and mitigate Bun segmentation faults
This commit is contained in:
parent
8ca945cdbd
commit
7820c5aade
1 changed files with 35 additions and 26 deletions
31
svr.js
31
svr.js
|
@ -191,6 +191,12 @@ if (!singlethreaded) {
|
||||||
fakeIPCConnection.end(message);
|
fakeIPCConnection.end(message);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
process.removeFakeIPC = function() {
|
||||||
|
// Close IPC server
|
||||||
|
process.send = function() {};
|
||||||
|
fakeIPCServer.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +264,8 @@ if (!singlethreaded) {
|
||||||
socket.on("end", function () {
|
socket.on("end", function () {
|
||||||
newWorker.emit("message", receivedData);
|
newWorker.emit("message", receivedData);
|
||||||
});
|
});
|
||||||
}).listen(os.platform() === "win32" ? path.join("\\\\?\\pipe", __dirname, "temp/.P" + newWorker.process.pid + ".ipc") : (__dirname + "/temp/.P" + newWorker.process.pid + ".ipc"));
|
});
|
||||||
|
fakeWorkerIPCServer.listen(os.platform() === "win32" ? path.join("\\\\?\\pipe", __dirname, "temp/.P" + newWorker.process.pid + ".ipc") : (__dirname + "/temp/.P" + newWorker.process.pid + ".ipc"));
|
||||||
|
|
||||||
// Cleanup when worker process exits
|
// Cleanup when worker process exits
|
||||||
newWorker.on("exit", function () {
|
newWorker.on("exit", function () {
|
||||||
|
@ -275,10 +282,13 @@ if (!singlethreaded) {
|
||||||
fakeWorkerIPCConnection.end(message);
|
fakeWorkerIPCConnection.end(message);
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (tries > 25) throw err;
|
if (tries > 25) {
|
||||||
|
newWorker.emit("error", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
newWorker.send(message, undefined, undefined, tries + 1);
|
newWorker.send(message, fakeParam2, fakeParam3, fakeParam4, tries + 1);
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -4803,14 +4813,10 @@ function start(init) {
|
||||||
var commands = {
|
var commands = {
|
||||||
close: function () {
|
close: function () {
|
||||||
try {
|
try {
|
||||||
if(server.listening || server2.listening) {
|
|
||||||
server.close();
|
server.close();
|
||||||
if (secure && !disableNonEncryptedServer) {
|
if (secure && !disableNonEncryptedServer) {
|
||||||
server2.close();
|
server2.close();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new Error("Server is already closed.");
|
|
||||||
}
|
|
||||||
if (cluster.isPrimary === undefined) serverconsole.climessage("Server closed.");
|
if (cluster.isPrimary === undefined) serverconsole.climessage("Server closed.");
|
||||||
else {
|
else {
|
||||||
process.send("Server closed.");
|
process.send("Server closed.");
|
||||||
|
@ -4823,16 +4829,12 @@ function start(init) {
|
||||||
},
|
},
|
||||||
open: function () {
|
open: function () {
|
||||||
try {
|
try {
|
||||||
if(!server.listening) {
|
|
||||||
if (secure) {
|
if (secure) {
|
||||||
server.listen(sport);
|
server.listen(sport);
|
||||||
if (!disableNonEncryptedServer) server2.listen(port);
|
if (!disableNonEncryptedServer) server2.listen(port);
|
||||||
} else {
|
} else {
|
||||||
server.listen(port); // Reopen Server
|
server.listen(port); // Reopen Server
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new Error("Server is already opened.");
|
|
||||||
}
|
|
||||||
if (cluster.isPrimary === undefined) serverconsole.climessage("Server opened.");
|
if (cluster.isPrimary === undefined) serverconsole.climessage("Server opened.");
|
||||||
else {
|
else {
|
||||||
process.send("Server opened.");
|
process.send("Server opened.");
|
||||||
|
@ -4866,26 +4868,32 @@ function start(init) {
|
||||||
if(server2.listening) {
|
if(server2.listening) {
|
||||||
try {
|
try {
|
||||||
server2.close(function() {
|
server2.close(function() {
|
||||||
|
if(!process.removeFakeIPC) {
|
||||||
if (typeof retcode == "number") {
|
if (typeof retcode == "number") {
|
||||||
process.exit(retcode);
|
process.exit(retcode);
|
||||||
} else {
|
} else {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
|
if(!process.removeFakeIPC) {
|
||||||
if (typeof retcode == "number") {
|
if (typeof retcode == "number") {
|
||||||
process.exit(retcode);
|
process.exit(retcode);
|
||||||
} else {
|
} else {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if(!process.removeFakeIPC) {
|
||||||
if (typeof retcode == "number") {
|
if (typeof retcode == "number") {
|
||||||
process.exit(retcode);
|
process.exit(retcode);
|
||||||
} else {
|
} else {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
if (typeof retcode == "number") {
|
if (typeof retcode == "number") {
|
||||||
|
@ -4894,6 +4902,7 @@ function start(init) {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(process.removeFakeIPC) process.removeFakeIPC();
|
||||||
} else {
|
} else {
|
||||||
if (typeof retcode == "number") {
|
if (typeof retcode == "number") {
|
||||||
process.exit(retcode);
|
process.exit(retcode);
|
||||||
|
|
Reference in a new issue