diff --git a/index.js b/index.js index 74693ed..6ae3343 100644 --- a/index.js +++ b/index.js @@ -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); @@ -189,7 +193,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.length > 0 && emulatedStdout._readableState.flowing !== null && !emulatedStdout.endEmitted) { emulatedStdout.on("end", function() { emulatedStderr.push(null); eventEmitter.emit("error", err); @@ -200,7 +204,7 @@ function createFastCGIHandler(options) { } } else { emulatedStdout.push(null); - if (emulatedStdout._readableState && emulatedStdout._readableState.length > 0 && emulatedStdout._readableState.flowing !== null) { + if (emulatedStdout._readableState && emulatedStdout._readableState.length > 0 && emulatedStdout._readableState.flowing !== null && !emulatedStdout.endEmitted) { emulatedStdout.on("end", function() { emulatedStderr.push(null); eventEmitter.emit("exit", appStatus, null);