mercurius-js / mercurius

Implement GraphQL servers and gateways with Fastify
https://mercurius.dev/
MIT License
2.36k stars 238 forks source link

Handle Redis pubsub subscription failures. #1114

Open PhanindraNeralla opened 1 month ago

PhanindraNeralla commented 1 month ago

We use fastify and mercurius. We also use graphql subscriptions using redis pubsub (graphql-redis-subscriptions and io-redis) and setting up the schema of Resolvers ( Queries, Mutations, Subscriptions) while registering mercurius plugin onto fastify server.

Now, once app is up and running and later if Redis is down due to any reason, subscriptions are erroring out and causing app to crash. ( Handled using redisClient.on('error') , process.on('unhandledExceptions') etc , but still it doesnt help ). Any idea how fastify/mercurius handles such cases? - like, we should be able to safely disable subscriptions OR return empty object for subscriptions while redis is down

My observations include, setting up error handlers only while setting up Fastify server. Not after that. i.e. Once server is running and we have Redis down, how can we make sure our Fastify server handle subscriptions gracefully.

mcollina commented 1 month ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.