hapijs/cookie

Does Boom.unauthorized in validate method cause HAPI handler to slow down?

mkukawski opened this issue · 1 comments

Support plan

  • is this issue currently blocking your project? (no):
  • is this issue affecting a production system? (yes):

Context

  • node version: 10.24.1
  • module version: 11.0.0
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): hapi
  • any other relevant information:

How can we help?

validate function checks for session first and if it's missing it throws Boom.unauthorized.
It looks like it produces exception with a stack trace.
In other programming languages driving logic using exceptions is causing the slowdown in processing the code.
Is that the case here?
It's especially relevant for HAPI routes that have 'try' setting where auth is optional and naturally session will be empty often times to begin with, so in these cases it's not really dramatic event...

   const scheme = {
        authenticate: function (request, reply) {

            const validate = function () {

                // Check cookie

                const session = request.state[settings.cookie];
                if (!session) {
                    return unauthenticated(Boom.unauthorized(null, 'cookie'));
                }
           //...
          }}}

Yes, errors are slow in node, especially if you read the .stack property.