Fix issue where "Request aborted" may be logged in res.sendfile

This commit is contained in:
Douglas Christopher Wilson 2018-09-19 23:25:16 -04:00
parent 5e9de5dcb6
commit 3d10279826
3 changed files with 19 additions and 10 deletions

View File

@ -1,6 +1,7 @@
unreleased
==========
* Fix issue where `"Request aborted"` may be logged in `res.sendfile`
* Fix JSDoc for `Router` constructor
* deps: body-parser@1.18.3
- Fix deprecation warnings on Node.js 10+

View File

@ -500,7 +500,7 @@ res.sendfile = function (path, options, callback) {
if (err && err.code === 'EISDIR') return next();
// next() all but write errors
if (err && err.code !== 'ECONNABORT' && err.syscall !== 'write') {
if (err && err.code !== 'ECONNABORTED' && err.syscall !== 'write') {
next(err);
}
});

View File

@ -96,25 +96,29 @@ describe('res', function(){
})
it('should not error if the client aborts', function (done) {
var cb = after(1, done);
var app = express();
var cb = after(2, done)
var error = null
app.use(function (req, res) {
setImmediate(function () {
res.sendFile(path.resolve(fixtures, 'name.txt'));
server.close(cb)
});
setTimeout(function () {
cb(error)
}, 10)
})
test.abort();
});
app.use(function (err, req, res, next) {
err.code.should.be.empty()
cb();
error = err
next(err)
});
var server = app.listen()
var test = request(server).get('/')
test.expect(200, cb);
test.end()
})
describe('with "cacheControl" option', function () {
@ -628,25 +632,29 @@ describe('res', function(){
});
it('should not error if the client aborts', function (done) {
var cb = after(1, done);
var app = express();
var cb = after(2, done)
var error = null
app.use(function (req, res) {
setImmediate(function () {
res.sendfile(path.resolve(fixtures, 'name.txt'));
server.close(cb)
setTimeout(function () {
cb(error)
}, 10)
});
test.abort();
});
app.use(function (err, req, res, next) {
err.code.should.be.empty()
cb();
error = err
next(err)
});
var server = app.listen()
var test = request(server).get('/')
test.expect(200, cb);
test.end()
})
describe('with an absolute path', function(){