Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inflight request throttle fix #1471

Merged
merged 2 commits into from Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/plugins/inflightRequestThrottle.js
Expand Up @@ -30,7 +30,7 @@ function inflightRequestThrottle (opts) {
assert.func(opts.server.inflightRequests, 'opts.server.inflightRequests');

if (opts.err !== undefined && opts.err !== null) {
assert.ok(opts.err instanceof Error, 'opts.res must be an error');
assert.ok(opts.err instanceof Error, 'opts.err must be an error');
assert.optionalNumber(opts.err.statusCode, 'opts.err.statusCode');
}

Expand All @@ -48,17 +48,14 @@ function inflightRequestThrottle (opts) {
inflightRequests: inflightRequests,
limit: self._limit
}, 'maximum inflight requests exceeded, rejecting request');
return res.send(self._err);
res.send(self._err);
return next(false);
}

return next();
}

// We need to bind in order to keep our `this` context when passed back
// out of the constructor.
return onRequest;
}

inflightRequestThrottle.prototype.onRequest =

module.exports = inflightRequestThrottle;
16 changes: 8 additions & 8 deletions test/plugins/inflightRequestThrottle.test.js
Expand Up @@ -25,9 +25,8 @@ describe('inlfightRequestThrottle', function () {
assert(body instanceof Error, 'Defaults to error body');
done();
}
function next () {
assert(false, 'Should not call next');
done();
function next (cont) {
assert.isFalse(cont, 'Should call next with false');
}
function trace () {
logged = true;
Expand All @@ -48,7 +47,6 @@ describe('inlfightRequestThrottle', function () {
}
function next () {
assert(false, 'Should not call next');
done();
}
var fakeReq = { log : { trace: function () {} } };
plugin(fakeReq, { send: send }, next);
Expand All @@ -59,10 +57,9 @@ describe('inlfightRequestThrottle', function () {
var plugin = inflightRequestThrottle(opts);
function send () {
assert(false, 'Should not call send');
done();
}
function next () {
assert(true, 'Should call next');
function next (cont) {
assert.isUndefined(cont, 'Should call next');
done();
}
var fakeReq = { log : { trace: function () {} } };
Expand Down Expand Up @@ -116,7 +113,10 @@ describe('inlfightRequestThrottle', function () {
'InternalServerError', 'Default err returned');
assert.equal(res.statusCode, 555,
'Default shed status code returned');
RES.send(200);

if (RES) {
RES.send(200);
}
});
});
});
Expand Down