fastify / under-pressure

Measure process load with automatic handling of "Service Unavailable" plugin for Fastify.
MIT License
341 stars 35 forks source link

Cannot read properties of undefined (reading 'pressureHandler') #232

Closed c0sx closed 1 month ago

c0sx commented 1 month ago

Prerequisites

Fastify version

4.13.0

Plugin version

8.5.1

Node.js version

v18.20.3

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.5 Sonoma

Description

I upgraded under-pressure plugin from 8.1 to the latest (8.5.1) and it failed with error

{
    "type": "TypeError",
     "message": "Cannot read properties of undefined (reading 'pressureHandler')",
     "stack":
          TypeError: Cannot read properties of undefined (reading 'pressureHandler')
              at Object.onRequest (/Users/tweekus/projects/platformeco/platformeco-fastify-connector/node_modules/@fastify/under-pressure/index.js:224:54)
              at hookIterator (/Users/tweekus/projects/platformeco/platformeco-fastify-connector/node_modules/fastify/lib/hooks.js:251:10)
              at next (/Users/tweekus/projects/platformeco/platformeco-fastify-connector/node_modules/fastify/lib/hooks.js:179:16)
              at handleResolve (/Users/tweekus/projects/platformeco/platformeco-fastify-connector/node_modules/fastify/lib/hooks.js:190:5)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
}

Link to code that reproduces the bug

I run tests for different versions of fastify server and it failed for 4.0.0-4.22.0 with error

Expected Behavior

I expects work like in 8.1 version

jean-michelet commented 1 month ago

We still need a link to a repo so we don't have to guess what you've written that causes this error.

Is this deprecation the reason of the error? https://github.com/fastify/under-pressure/issues/220

c0sx commented 1 month ago

We still need a link to a repo so we don't have to guess what you've written that causes this error.

Sure, https://github.com/c0sx/fastify-under-pressure/blob/main/index.js (just run it and open localhost:3000)

Is this deprecation the reason of the error? #220

No, deprecation message is not a reason, but fix - yes

Uzlopak commented 1 month ago

image

c0sx commented 1 month ago

I could add PR with fix if you don't mind

c0sx commented 1 month ago

Any news?

Eomm commented 1 month ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests and to target the v8.x branch for fastify v4 and the main one for fastify v5.

c0sx commented 1 month ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests and to target the v8.x branch for fastify v4 and the main one for fastify v5.

Yeah. I didn't think that fastify v5 have this problem but I'll check

jean-michelet commented 1 month ago

Thanks @c0sx!