-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Re-posting here as advised in apollographql/apollo-server#7688. Without digging into source code I'm not exactly sure which part of graphql-js is causing this.
Issue Description
We've identified a potential resource exhaustion vector which has a significant impact on our CPU and response times. We're currently experiencing this on AS 3 however we're able to reproduce on AS 4.
We have a custom query complexity calc plugin which is intended to handle this scenario and others however it seems before we get to didResolveOperation
event/stage, there is some processing that takes a long time.
I'm assuming this is an underlying dependancy in Apollo however I'm not 100% sure so any ideas or suggestions on how we can mitigate this would be great.
Link to Reproduction
https://github.com/tadhglewis/apollo-koa-minimal
Reproduction Steps
pnpm install && pnpm start
- Run
curl \
--data "{\"query\":\"{ $(python3 -c "print('%s' % ('__typename ' * 1000))")}\"}" \
--header 'Content-Type: application/json' \
--include \
--request POST \
https://example.com/graphql
This will take ~2.5s and increase to ~21s if you change the number of __typename
to 3000

Notes
- On subsequent requests there seems to be some caching and response time goes to ~10ms however if you change the number of
__typename
by one it will bypass this - This isn't limited to
__typename
, it can also be hit when usinghello
and I imagine introspection as well