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); var processedPacket = parseFastCGIPacket(packet);
if (processedPacket.requestID != requestID) return; //Drop the packet if (processedPacket.requestID != requestID) return; //Drop the packet
if (processedPacket.type == STDOUT) { if (processedPacket.type == STDOUT) {
try {
if(processedPacket.content.length > 0) emulatedStdout.push(processedPacket.content); 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) { } else if (processedPacket.type == STDERR) {
try { try {
if(processedPacket.content.length > 0) emulatedStderr.push(processedPacket.content); if(processedPacket.content.length > 0) emulatedStderr.push(processedPacket.content);
@ -174,7 +178,10 @@ function createFastCGIHandler(options) {
//STDERR will be lost anyway... //STDERR will be lost anyway...
} }
} else if (processedPacket.type == END_REQUEST && processedPacket.content.length > 5) { } 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 appStatus = processedPacket.content.readUInt32BE(0);
var protocolStatus = processedPacket.content.readUInt8(4); var protocolStatus = processedPacket.content.readUInt8(4);
if (protocolStatus != REQUEST_COMPLETE) { if (protocolStatus != REQUEST_COMPLETE) {
@ -189,7 +196,7 @@ function createFastCGIHandler(options) {
err = new Error("Multiplexed connections not supported by the FastCGI application"); err = new Error("Multiplexed connections not supported by the FastCGI application");
} }
emulatedStdout.push(null); 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() { emulatedStdout.on("end", function() {
emulatedStderr.push(null); emulatedStderr.push(null);
eventEmitter.emit("error", err); eventEmitter.emit("error", err);
@ -200,7 +207,7 @@ function createFastCGIHandler(options) {
} }
} else { } else {
emulatedStdout.push(null); 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() { emulatedStdout.on("end", function() {
emulatedStderr.push(null); emulatedStderr.push(null);
eventEmitter.emit("exit", appStatus, null); eventEmitter.emit("exit", appStatus, null);
@ -279,6 +286,8 @@ function createFastCGIHandler(options) {
eventEmitter.emit("error", err); eventEmitter.emit("error", err);
}).on("data", fastCGISocketHandler); }).on("data", fastCGISocketHandler);
eventEmitter.socket = socket;
return eventEmitter; 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.init();
handler.stdout.on("data", dataHandler); handler.stdout.on("data", dataHandler);
handler.stderr.on("data", function (data) { handler.stderr.on("data", function (data) {
@ -484,10 +497,12 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
serverconsole.errmessage(preparedStderr); serverconsole.errmessage(preparedStderr);
} }
handler.stdout.unpipe(res); //Prevent server crashes with write after the end 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) { 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", "name": "GreenRhombus FastCGI client for SVR.JS",
"version": "1.0.2" "version": "1.0.3"
} }