Skip to content

Commit b3f2eb5

Browse files
authored
remove route timeout assertions (#4123)
This commit removes the artificial constraint that the server timeout and the payload timeout must be less than the socket idle timeout.
1 parent 501a264 commit b3f2eb5

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

lib/route.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ exports = module.exports = internals.Route = class {
8383
const settings = internals.config([core.settings.routes, handlerDefaults, realm.settings, rulesConfig, config]);
8484
this.settings = Config.apply('routeConfig', settings, method, path);
8585

86-
// Validate timeouts
87-
88-
const socketTimeout = this.settings.timeout.socket === undefined ? 2 * 60 * 1000 : this.settings.timeout.socket;
89-
this._assert(!this.settings.timeout.server || !socketTimeout || this.settings.timeout.server < socketTimeout, 'Server timeout must be shorter than socket timeout');
90-
this._assert(!this.settings.payload.timeout || !socketTimeout || this.settings.payload.timeout < socketTimeout, 'Payload timeout must be shorter than socket timeout');
9186

9287
// Route members
9388

test/route.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,22 @@ describe('Route', () => {
326326
expect(called).to.be.false();
327327
});
328328

329+
it('throws error when the default routes payload validation is set without payload parsing', () => {
330+
331+
expect(() => {
332+
333+
Hapi.server({ routes: { validate: { payload: {}, validator: Joi }, payload: { parse: false } } });
334+
}).to.throw('Route payload must be set to \'parse\' when payload validation enabled');
335+
});
336+
337+
it('throws error when the default routes state validation is set without state parsing', () => {
338+
339+
expect(() => {
340+
341+
Hapi.server({ routes: { validate: { state: {}, validator: Joi }, state: { parse: false } } });
342+
}).to.throw('Route state must be set to \'parse\' when state validation enabled');
343+
});
344+
329345
it('ignores default validation on GET', async () => {
330346

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

453-
it('throws when server timeout is more then socket timeout', () => {
469+
it('allows payload timeout more then socket timeout', () => {
470+
471+
expect(() => {
472+
473+
Hapi.server({ routes: { payload: { timeout: 60000 }, timeout: { socket: 12000 } } });
474+
}).to.not.throw();
475+
});
476+
477+
it('allows payload timeout more then socket timeout (node default)', () => {
478+
479+
expect(() => {
480+
481+
Hapi.server({ routes: { payload: { timeout: 6000000 } } });
482+
}).to.not.throw();
483+
});
484+
485+
it('allows server timeout more then socket timeout', () => {
454486

455487
expect(() => {
456488

457489
Hapi.server({ routes: { timeout: { server: 60000, socket: 12000 } } });
458-
}).to.throw('Server timeout must be shorter than socket timeout');
490+
}).to.not.throw();
459491
});
460492

461-
it('throws when server timeout is more then socket timeout (node default)', () => {
493+
it('allows server timeout more then socket timeout (node default)', () => {
462494

463495
expect(() => {
464496

465497
Hapi.server({ routes: { timeout: { server: 6000000 } } });
466-
}).to.throw('Server timeout must be shorter than socket timeout');
498+
}).to.not.throw();
467499
});
468500

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

0 commit comments

Comments
 (0)