n1ru4l / envelop

Envelop is a lightweight library allowing developers to easily develop, share, collaborate and extend their GraphQL execution layer. Envelop is the missing GraphQL plugin system.
https://envelop.dev
MIT License
771 stars 119 forks source link

[useResponseCache] Promise rejections from cache impl are not handled #2240

Open sachinahya opened 2 months ago

sachinahya commented 2 months ago

Issue workflow progress

Progress of the issue based on the Contributor Workflow


Describe the bug

The cache implementation can be sync or async - each of the methods can return a Promise. However, these promises are not awaited or handled so they end up as "floating promises". When one of these rejects, Node treats it as an unhandled promise rejection and, under default behaviour

To Reproduce Steps to reproduce the behavior:

  1. Set up response cache with graphql-yoga in Node.
  2. Override the cache with an implementation of set which returns a rejected promise.
  3. Execute a query that would be cached.
  4. The result returns since cache.set isn't awaited, but in the background the Node processes crashes.

We noticed this whilst using @envelop/response-cache-redis with a Redis setup that wasn't configured correctly, however, the incorrect error handling can be reproduced with anything that returns a rejected promise.

Expected behavior

The rejected promise should be returned through onExecuteDone so it can be handled by the server and result in a failed request. The process should not get terminated.

Environment: