Update to GreenRhombus 1.0.3

This commit is contained in:
Dorian Niemiec 2024-02-21 02:00:21 +01:00
parent 6b2e88c6ab
commit ae8ae208c4
2 changed files with 23 additions and 8 deletions

View file

@ -166,7 +166,11 @@ function createFastCGIHandler(options) {
var processedPacket = parseFastCGIPacket(packet);
if (processedPacket.requestID != requestID) return; //Drop the packet
if (processedPacket.type == STDOUT) {
if(processedPacket.content.length > 0) emulatedStdout.push(processedPacket.content);
try {
if(processedPacket.content.length > 0) emulatedStdout.push(processedPacket.content);
} catch (err) {
//STDOUT will be lost instead of crashing the server
}
} else if (processedPacket.type == STDERR) {
try {
if(processedPacket.content.length > 0) emulatedStderr.push(processedPacket.content);
@ -174,7 +178,10 @@ function createFastCGIHandler(options) {
//STDERR will be lost anyway...
}
} else if (processedPacket.type == END_REQUEST && processedPacket.content.length > 5) {
if (typeof socket !== "undefined") socket.removeListener("data", fastCGISocketHandler);
if (typeof socket !== "undefined") {
socket.removeListener("data", fastCGISocketHandler);
processFastCGIPacket = function() {};
}
var appStatus = processedPacket.content.readUInt32BE(0);
var protocolStatus = processedPacket.content.readUInt8(4);
if (protocolStatus != REQUEST_COMPLETE) {
@ -189,7 +196,7 @@ function createFastCGIHandler(options) {
err = new Error("Multiplexed connections not supported by the FastCGI application");
}
emulatedStdout.push(null);
if (emulatedStdout._readableState && emulatedStdout._readableState.length > 0 && emulatedStdout._readableState.flowing !== null) {
if (emulatedStdout._readableState && emulatedStdout._readableState.flowing !== null && !emulatedStdout.endEmitted) {
emulatedStdout.on("end", function() {
emulatedStderr.push(null);
eventEmitter.emit("error", err);
@ -200,7 +207,7 @@ function createFastCGIHandler(options) {
}
} else {
emulatedStdout.push(null);
if (emulatedStdout._readableState && emulatedStdout._readableState.length > 0 && emulatedStdout._readableState.flowing !== null) {
if (emulatedStdout._readableState && emulatedStdout._readableState.flowing !== null && !emulatedStdout.endEmitted) {
emulatedStdout.on("end", function() {
emulatedStderr.push(null);
eventEmitter.emit("exit", appStatus, null);
@ -279,6 +286,8 @@ function createFastCGIHandler(options) {
eventEmitter.emit("error", err);
}).on("data", fastCGISocketHandler);
eventEmitter.socket = socket;
return eventEmitter;
}
@ -461,7 +470,11 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
}
});
handler.on("connect", function () {
res.on("close", function() {
if(handler.stdout) handler.stdout.unpipe(res); //Prevent server crashes with write after the end
});
function handlerConnection() {
handler.init();
handler.stdout.on("data", dataHandler);
handler.stderr.on("data", function (data) {
@ -484,10 +497,12 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
serverconsole.errmessage(preparedStderr);
}
handler.stdout.unpipe(res); //Prevent server crashes with write after the end
res.end();
if(!res.finished) res.end();
}
});
});
}
if(typeof handler.socket.connecting == "undefined" || handler.socket.connecting) handler.on("connect", handlerConnection);
else if(!handler.socket.destroyed) handlerConnection();
}
function executeFastCGIWithEnv(a, b, req, res, pubip, port, software, dh, user, cPath) {

View file

@ -1,4 +1,4 @@
{
"name": "GreenRhombus FastCGI client for SVR.JS",
"version": "1.0.2"
"version": "1.0.3"
}