Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle failed subscription payloads #7866

Merged
merged 4 commits into from Apr 5, 2024

Conversation

tninesling
Copy link
Contributor

Currently, the error handling for subscription events is not well-defined in the GraphQL spec, but that doesn't mean we shouldn't handle them! The existing behavior is that an error thrown from a subscription's generator will go uncaught and crash the whole server.

For a transient failure, it may be preferable for consumers that we simply return an error response and continue waiting for more data from the iterator, in case the producer recovers and resumes producing valid data. However, Node's AsyncGenerator terminates once an error is thrown, even if you manually loop calling iterator.next().

This change wraps the iterator consumption in a try/catch and closes the subscription when an error is encountered. Propagating the error up to the subscriber will allow them to decide if they need to resubscribe or not, in the case of a transient error.

Copy link

netlify bot commented Apr 4, 2024

Deploy Preview for apollo-server-docs ready!

Name Link
🔨 Latest commit 327eef5
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/660f2ef1b5d6210008d15207
😎 Deploy Preview https://deploy-preview-7866--apollo-server-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tninesling tninesling changed the title Tninesling/handle failed subscription payloads Handle failed subscription payloads Apr 4, 2024
Copy link

codesandbox-ci bot commented Apr 4, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Member

@IvanGoncharov IvanGoncharov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a simple fit to me 👍

@tninesling tninesling merged commit 5f335a5 into main Apr 5, 2024
24 checks passed
@tninesling tninesling deleted the tninesling/handle-failed-subscription-payloads branch April 5, 2024 15:16
@github-actions github-actions bot mentioned this pull request Apr 5, 2024
tninesling pushed a commit that referenced this pull request Apr 15, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @apollo/server-integration-testsuite@4.10.3

### Patch Changes

- Updated dependencies
\[[`5f335a5`](5f335a5)]:
    -   @apollo/server@4.10.3

## @apollo/server@4.10.3

### Patch Changes

- [#7866](#7866)
[`5f335a5`](5f335a5)
Thanks [@tninesling](https://github.com/tninesling)! - Catch errors
thrown by subscription generators, and gracefully clean up the
subscription instead of crashing.

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants