Skip to content

Commit 3d10279

Browse files
committed
Fix issue where "Request aborted" may be logged in res.sendfile
1 parent 5e9de5d commit 3d10279

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33

4+
* Fix issue where `"Request aborted"` may be logged in `res.sendfile`
45
* Fix JSDoc for `Router` constructor
56
67
- Fix deprecation warnings on Node.js 10+

lib/response.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ res.sendfile = function (path, options, callback) {
500500
if (err && err.code === 'EISDIR') return next();
501501

502502
// next() all but write errors
503-
if (err && err.code !== 'ECONNABORT' && err.syscall !== 'write') {
503+
if (err && err.code !== 'ECONNABORTED' && err.syscall !== 'write') {
504504
next(err);
505505
}
506506
});

test/res.sendFile.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,29 @@ describe('res', function(){
9696
})
9797

9898
it('should not error if the client aborts', function (done) {
99-
var cb = after(1, done);
10099
var app = express();
100+
var cb = after(2, done)
101+
var error = null
101102

102103
app.use(function (req, res) {
103104
setImmediate(function () {
104105
res.sendFile(path.resolve(fixtures, 'name.txt'));
105106
server.close(cb)
106-
});
107+
setTimeout(function () {
108+
cb(error)
109+
}, 10)
110+
})
107111
test.abort();
108112
});
109113

110114
app.use(function (err, req, res, next) {
111-
err.code.should.be.empty()
112-
cb();
115+
error = err
116+
next(err)
113117
});
114118

115119
var server = app.listen()
116120
var test = request(server).get('/')
117-
test.expect(200, cb);
121+
test.end()
118122
})
119123

120124
describe('with "cacheControl" option', function () {
@@ -628,25 +632,29 @@ describe('res', function(){
628632
});
629633

630634
it('should not error if the client aborts', function (done) {
631-
var cb = after(1, done);
632635
var app = express();
636+
var cb = after(2, done)
637+
var error = null
633638

634639
app.use(function (req, res) {
635640
setImmediate(function () {
636641
res.sendfile(path.resolve(fixtures, 'name.txt'));
637642
server.close(cb)
643+
setTimeout(function () {
644+
cb(error)
645+
}, 10)
638646
});
639647
test.abort();
640648
});
641649

642650
app.use(function (err, req, res, next) {
643-
err.code.should.be.empty()
644-
cb();
651+
error = err
652+
next(err)
645653
});
646654

647655
var server = app.listen()
648656
var test = request(server).get('/')
649-
test.expect(200, cb);
657+
test.end()
650658
})
651659

652660
describe('with an absolute path', function(){

0 commit comments

Comments
 (0)