Skip to content

Fix errors handling in GraphQL subscriptions#1371

Merged
tyranron merged 5 commits intographql-rust:masterfrom
50U10FCA7:subscription-panic-handler
Mar 14, 2026
Merged

Fix errors handling in GraphQL subscriptions#1371
tyranron merged 5 commits intographql-rust:masterfrom
50U10FCA7:subscription-panic-handler

Conversation

@50U10FCA7
Copy link
Contributor

@50U10FCA7 50U10FCA7 commented Mar 13, 2026

Synopsis

juniper_graphql_ws doesn't allow end-user to handle panics can happen during resolvers/streams execution.

Also, current implementation of #[graphql_subscription] maps errors incorrectly, which causes memory leak and completely omits errors in GraphQL subscriptions:

Omitted errors in GraphQL subscriptions

Each subscription resolves items of its stream, expecting the resolving can fail which is never happens because of the GraphQL specification. And because of this, no errors passed to GraphQL subscription leaving them inside the Executor.

Memory leak

juniper::Executor is shared across all the subscription's items (one executor per subscription). And its errors shared across all the types resolution. Executor::errors in current implementation only collects errors but never Drops them, which can lead to a memory leak in long-running subscription regularly emitting errors.

Solution

  • Support panic handling in juniper_graphql_ws crate.
  • Fix errors mapping in #[graphql_subscription] macro expansion.
  • Fix memory leak caused by error handling in GraphQL subscriptions.
  • Make juniper::ValuesStream to support error batching.

Checklist

  • Tests are added
  • Documentation is added (including Book)
  • CHANGELOG is filled

@50U10FCA7 50U10FCA7 marked this pull request as ready for review March 13, 2026 23:50
@50U10FCA7
Copy link
Contributor Author

FCM

Fix errors handling in GraphQL subscriptions (#1371)

- support panic handling in `juniper_graphql_ws` crate
- fix errors mapping in `#[graphql_subscription]` macro expansion in `juniper_codegen` crate
- fix memory leak caused by incorrect errors handling in GraphQL subscriptions machinery
- refactor `juniper::ValuesStream` to support error batching in `juniper` crate

@tyranron tyranron added enhancement Improvement of existing features or bugfix area::subscriptions Related to GraphQL subscriptions k::refactor Refactoring, technical debt elimination and other improvements of existing code base labels Mar 14, 2026
@tyranron tyranron added this to the 0.18.0 milestone Mar 14, 2026
@tyranron tyranron added the semver::breaking Breaking change in terms of SemVer label Mar 14, 2026
@tyranron tyranron merged commit d6918a8 into graphql-rust:master Mar 14, 2026
539 of 543 checks passed
@50U10FCA7 50U10FCA7 deleted the subscription-panic-handler branch March 14, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area::subscriptions Related to GraphQL subscriptions enhancement Improvement of existing features or bugfix k::refactor Refactoring, technical debt elimination and other improvements of existing code base semver::breaking Breaking change in terms of SemVer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants