Fix "write after end" server crashes
This commit is contained in:
parent
7307229e90
commit
3d5d57b7b4
1 changed files with 11 additions and 1 deletions
12
index.js
12
index.js
|
@ -297,9 +297,17 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
|||
res.write(data);
|
||||
interpreter.stdout.removeListener("data", dataHandler);
|
||||
interpreter.stdout.pipe(res, {end: false});
|
||||
dataHandler = function () {}; //Prevent event listener memory leaks
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
res.prependListener("close", function() {
|
||||
if(handler.stdout) handler.stdout.unpipe(res); //Prevent server crashes with write after the end
|
||||
});
|
||||
|
||||
res.on("error", function() {}); //Suppress response stream errors
|
||||
|
||||
if (interpreter.stdout) {
|
||||
interpreter.stdout.on("data", dataHandler);
|
||||
interpreter.stderr.on("data", function (data) {
|
||||
|
@ -321,7 +329,9 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
|
|||
serverconsole.errmessage("There were CGI application errors:");
|
||||
serverconsole.errmessage(preparedStderr);
|
||||
}
|
||||
res.end();
|
||||
interpreter.stdout.removeListener("data", dataHandler);
|
||||
interpreter.stdout.unpipe(res); //Prevent server crashes with write after the end
|
||||
if(!res.finished) res.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue