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);
|
||||
});
|
||||
};
|
||||
|
||||
process.removeFakeIPC = function() {
|
||||
// Close IPC server
|
||||
process.send = function() {};
|
||||
fakeIPCServer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,7 +264,8 @@ if (!singlethreaded) {
|
|||
socket.on("end", function () {
|
||||
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
|
||||
newWorker.on("exit", function () {
|
||||
|
@ -275,10 +282,13 @@ if (!singlethreaded) {
|
|||
fakeWorkerIPCConnection.end(message);
|
||||
});
|
||||
} catch (err) {
|
||||
if (tries > 25) throw err;
|
||||
if (tries > 25) {
|
||||
newWorker.emit("error", err);
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
newWorker.send(message, undefined, undefined, tries + 1);
|
||||
newWorker.send(message, fakeParam2, fakeParam3, fakeParam4, tries + 1);
|
||||
}, 10);
|
||||
}
|
||||
};
|
||||
|
@ -4803,14 +4813,10 @@ function start(init) {
|
|||
var commands = {
|
||||
close: function () {
|
||||
try {
|
||||
if(server.listening || server2.listening) {
|
||||
server.close();
|
||||
if (secure && !disableNonEncryptedServer) {
|
||||
server2.close();
|
||||
}
|
||||
} else {
|
||||
throw new Error("Server is already closed.");
|
||||
}
|
||||
if (cluster.isPrimary === undefined) serverconsole.climessage("Server closed.");
|
||||
else {
|
||||
process.send("Server closed.");
|
||||
|
@ -4823,16 +4829,12 @@ function start(init) {
|
|||
},
|
||||
open: function () {
|
||||
try {
|
||||
if(!server.listening) {
|
||||
if (secure) {
|
||||
server.listen(sport);
|
||||
if (!disableNonEncryptedServer) server2.listen(port);
|
||||
} else {
|
||||
server.listen(port); // Reopen Server
|
||||
}
|
||||
} else {
|
||||
throw new Error("Server is already opened.");
|
||||
}
|
||||
if (cluster.isPrimary === undefined) serverconsole.climessage("Server opened.");
|
||||
else {
|
||||
process.send("Server opened.");
|
||||
|
@ -4866,26 +4868,32 @@ function start(init) {
|
|||
if(server2.listening) {
|
||||
try {
|
||||
server2.close(function() {
|
||||
if(!process.removeFakeIPC) {
|
||||
if (typeof retcode == "number") {
|
||||
process.exit(retcode);
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(err) {
|
||||
if(!process.removeFakeIPC) {
|
||||
if (typeof retcode == "number") {
|
||||
process.exit(retcode);
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(!process.removeFakeIPC) {
|
||||
if (typeof retcode == "number") {
|
||||
process.exit(retcode);
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(err) {
|
||||
if (typeof retcode == "number") {
|
||||
|
@ -4894,6 +4902,7 @@ function start(init) {
|
|||
process.exit(0);
|
||||
}
|
||||
}
|
||||
if(process.removeFakeIPC) process.removeFakeIPC();
|
||||
} else {
|
||||
if (typeof retcode == "number") {
|
||||
process.exit(retcode);
|
||||
|
|
Reference in a new issue