From b326ae89df48faac64f22be0eca0a86c87b203ee Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 23 Nov 2014 16:53:11 -0500 Subject: [PATCH] Fix res.sendFile logging standard write errors fixes #2433 --- History.md | 1 + lib/response.js | 4 ++-- test/res.sendFile.js | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index 825a28f8..895ddb1a 100644 --- a/History.md +++ b/History.md @@ -1,6 +1,7 @@ unreleased ========== + * Fix `res.sendFile` logging standard write errors * deps: etag@~1.5.1 * deps: proxy-addr@~1.0.4 - deps: ipaddr.js@0.1.5 diff --git a/lib/response.js b/lib/response.js index 34e46ad7..4dc08f77 100644 --- a/lib/response.js +++ b/lib/response.js @@ -398,8 +398,8 @@ res.sendFile = function sendFile(path, options, fn) { if (fn) return fn(err); if (err && err.code === 'EISDIR') return next(); - // next() all but aborted errors - if (err && err.code !== 'ECONNABORT') { + // next() all but write errors + if (err && err.code !== 'ECONNABORT' && err.syscall !== 'write') { next(err); } }); diff --git a/test/res.sendFile.js b/test/res.sendFile.js index 779f6ca7..c7631bb5 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -69,6 +69,27 @@ describe('res', function(){ .end(done); }) + it('should not error if the client aborts', function (done) { + var cb = after(1, done); + var app = express(); + + app.use(function (req, res) { + setImmediate(function () { + res.sendFile(path.resolve(fixtures, 'name.txt')); + cb(); + }); + test.abort(); + }); + + app.use(function (err, req, res, next) { + err.code.should.be.empty; + cb(); + }); + + var test = request(app).get('/'); + test.expect(200, cb); + }) + describe('with "dotfiles" option', function () { it('should not serve dotfiles by default', function (done) { var app = createApp(path.resolve(__dirname, 'fixtures/.name'));