Skip to content

Commit

Permalink
remove route timeout assertions (#4123)
Browse files Browse the repository at this point in the history
This commit removes the artificial constraint that the server timeout
and the payload timeout must be less than the socket idle timeout.
  • Loading branch information
kobelb authored Aug 11, 2020
1 parent 501a264 commit b3f2eb5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
5 changes: 0 additions & 5 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ exports = module.exports = internals.Route = class {
const settings = internals.config([core.settings.routes, handlerDefaults, realm.settings, rulesConfig, config]);
this.settings = Config.apply('routeConfig', settings, method, path);

// Validate timeouts

const socketTimeout = this.settings.timeout.socket === undefined ? 2 * 60 * 1000 : this.settings.timeout.socket;
this._assert(!this.settings.timeout.server || !socketTimeout || this.settings.timeout.server < socketTimeout, 'Server timeout must be shorter than socket timeout');
this._assert(!this.settings.payload.timeout || !socketTimeout || this.settings.payload.timeout < socketTimeout, 'Payload timeout must be shorter than socket timeout');

// Route members

Expand Down
40 changes: 36 additions & 4 deletions test/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,22 @@ describe('Route', () => {
expect(called).to.be.false();
});

it('throws error when the default routes payload validation is set without payload parsing', () => {

expect(() => {

Hapi.server({ routes: { validate: { payload: {}, validator: Joi }, payload: { parse: false } } });
}).to.throw('Route payload must be set to \'parse\' when payload validation enabled');
});

it('throws error when the default routes state validation is set without state parsing', () => {

expect(() => {

Hapi.server({ routes: { validate: { state: {}, validator: Joi }, state: { parse: false } } });
}).to.throw('Route state must be set to \'parse\' when state validation enabled');
});

it('ignores default validation on GET', async () => {

const server = Hapi.server({ routes: { validate: { payload: { a: Joi.required() }, validator: Joi } } });
Expand Down Expand Up @@ -450,20 +466,36 @@ describe('Route', () => {
expect(res.payload).to.contain('hapi');
});

it('throws when server timeout is more then socket timeout', () => {
it('allows payload timeout more then socket timeout', () => {

expect(() => {

Hapi.server({ routes: { payload: { timeout: 60000 }, timeout: { socket: 12000 } } });
}).to.not.throw();
});

it('allows payload timeout more then socket timeout (node default)', () => {

expect(() => {

Hapi.server({ routes: { payload: { timeout: 6000000 } } });
}).to.not.throw();
});

it('allows server timeout more then socket timeout', () => {

expect(() => {

Hapi.server({ routes: { timeout: { server: 60000, socket: 12000 } } });
}).to.throw('Server timeout must be shorter than socket timeout');
}).to.not.throw();
});

it('throws when server timeout is more then socket timeout (node default)', () => {
it('allows server timeout more then socket timeout (node default)', () => {

expect(() => {

Hapi.server({ routes: { timeout: { server: 6000000 } } });
}).to.throw('Server timeout must be shorter than socket timeout');
}).to.not.throw();
});

it('ignores large server timeout when socket timeout disabled', () => {
Expand Down

0 comments on commit b3f2eb5

Please sign in to comment.