diff --git a/lib/Response.js b/lib/Response.js index 1e5089c..4d20999 100644 --- a/lib/Response.js +++ b/lib/Response.js @@ -261,11 +261,12 @@ function sendFinalPayload(res, payload) { } function sendStream(payload, resStream, res) { - var sourceOpen = true + var payloadOpen = true + var resOpen = true eos(payload, {readable: true, writable: false}, (err) => { - sourceOpen = false - if (!err) { + payloadOpen = false + if (!err || !resOpen) { return } @@ -279,7 +280,8 @@ function sendStream(payload, resStream, res) { }) eos(resStream, (err) => { - if (err && sourceOpen) { + resOpen = false + if (err && payloadOpen) { res.route.onStreamError(err) destroyStream(payload) }