graphql-hive / graphql-hive/envelop

[useResponseCache] Promise rejections from cache impl are not handled

Open
#2,240 0 comments 0 reactions 0 assignees View on GitHub
kind/bug stage/4-pull-request
Dominant language
No language data
Stars
827
Forks
132
PR merge metrics
No merged PRs in 30d

Description

### Issue workflow progress

_Progress of the issue based on the
[Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_

- [ ] 1. The issue provides a
[minimal reproduction](https://en.wikipedia.org/wiki/Minimal_reproducible_example) available on
[Stackblitz](https://stackblitz.com/fork/node).
- _Please install the latest `@envelop/*` packages that you are using._
- _Please make sure the reproduction is as small as possible._
- [x] 2. A failing test has been provided
- [x] 3. A local solution has been provided
- [x] 4. A pull request is pending review

---

**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](https://the-guild.dev/graphql/yoga-server/docs/features/response-caching) 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:**

- OS: macOS 14.4.1
- NodeJS: v20.11.0
- `@envelop/*` versions:
- `@envelop/response-cache`: `6.1.2`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.