Prevented server crashes caused by header write errors. Also adapted RedBrick patches to OrangeCircle

This commit is contained in:
Dorian Niemiec 2024-02-16 02:35:20 +01:00
parent d75c6ce955
commit 1680398db2

View file

@ -89,6 +89,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
} }
var abheaders = JSON.parse(JSON.stringify(bheaders)); var abheaders = JSON.parse(JSON.stringify(bheaders));
var socket = {};
function executeSCGI(req, res, dh, nEnv) { function executeSCGI(req, res, dh, nEnv) {
// Function to execute SCGI scripts // Function to execute SCGI scripts
@ -152,6 +153,8 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
res.writeHead(code, msg, bheaderso); res.writeHead(code, msg, bheaderso);
res.write(buffer.substr(headerendline + eol.length), "latin1"); res.write(buffer.substr(headerendline + eol.length), "latin1");
} catch (ex) { } catch (ex) {
socket.removeAllListeners("data");
socket.removeAllListeners("end");
if (!callServerError) { if (!callServerError) {
res.writeHead(500); res.writeHead(500);
res.end(ex.stack); res.end(ex.stack);
@ -163,13 +166,13 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
} else { } else {
if (cned && !res.finished) { if (cned && !res.finished) {
res.write(data); res.write(data);
interpreter.stdout.removeListener("data", dataHandler); socket.removeListener("data", dataHandler);
interpreter.stdout.pipe(res, {end: false}); socket.pipe(res, {end: false});
} }
} }
}; };
var socket = net.createConnection({ socket = net.createConnection({
host: scgiConf.host, host: scgiConf.host,
port: scgiConf.port, port: scgiConf.port,
}, function () { }, function () {